Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

CRISv10 serial driver rewrite

New and improved serial driver for CRISv10, take three, with improvements
suggested by Jiri Slaby.

- Call wait_event_interruptible with a _correct_ and sensible condition.
- Removed superfluous test of info->flags & ASYNC_CLOSING, since that is done
by wait_event_interruptible.
- Moved common code for deregistering DMA and IRQ to deinit_port function.
- Use setup_timer when initializing flush_timer.
- Convert bit-field for uses_dma_in and uses_dma_out to regular bytes.
- Removed CVS tags.
- Removed defines and comments for CRIS_BUF_SIZE and TTY_THRESHOLD_THROTTLE
(no longer used).
- Cleaned up code to pass checkpatch.
- Add crisv10.h header file.
- Merge of CRISv10 from Axis internal CVS.

Signed-off-by: Jesper Nilsson <jesper.nilsson@axis.com>
Reviewed-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Mikael Starvik <starvik@axis.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jesper Nilsson and committed by
Linus Torvalds
77accbf5 4b7e8889

+581 -860
+435 -860
drivers/serial/crisv10.c
··· 1 - /* $Id: serial.c,v 1.25 2004/09/29 10:33:49 starvik Exp $ 2 - * 1 + /* 3 2 * Serial port driver for the ETRAX 100LX chip 4 3 * 5 - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Axis Communications AB 4 + * Copyright (C) 1998-2007 Axis Communications AB 6 5 * 7 6 * Many, many authors. Based once upon a time on serial.c for 16x50. 8 - * 9 - * $Log: serial.c,v $ 10 - * Revision 1.25 2004/09/29 10:33:49 starvik 11 - * Resolved a dealock when printing debug from kernel. 12 - * 13 - * Revision 1.24 2004/08/27 23:25:59 johana 14 - * rs_set_termios() must call change_speed() if c_iflag has changed or 15 - * automatic XOFF handling will be enabled and transmitter will stop 16 - * if 0x13 is received. 17 - * 18 - * Revision 1.23 2004/08/24 06:57:13 starvik 19 - * More whitespace cleanup 20 - * 21 - * Revision 1.22 2004/08/24 06:12:20 starvik 22 - * Whitespace cleanup 23 - * 24 - * Revision 1.20 2004/05/24 12:00:20 starvik 25 - * Big merge of stuff from Linux 2.4 (e.g. manual mode for the serial port). 26 - * 27 - * Revision 1.19 2004/05/17 13:12:15 starvik 28 - * Kernel console hook 29 - * Big merge from Linux 2.4 still pending. 30 - * 31 - * Revision 1.18 2003/10/28 07:18:30 starvik 32 - * Compiles with debug info 33 - * 34 - * Revision 1.17 2003/07/04 08:27:37 starvik 35 - * Merge of Linux 2.5.74 36 - * 37 - * Revision 1.16 2003/06/13 10:05:19 johana 38 - * Help the user to avoid trouble by: 39 - * Forcing mixed mode for status/control lines if not all pins are used. 40 - * 41 - * Revision 1.15 2003/06/13 09:43:01 johana 42 - * Merged in the following changes from os/linux/arch/cris/drivers/serial.c 43 - * + some minor changes to reduce diff. 44 - * 45 - * Revision 1.49 2003/05/30 11:31:54 johana 46 - * Merged in change-branch--serial9bit that adds CMSPAR support for sticky 47 - * parity (mark/space) 48 - * 49 - * Revision 1.48 2003/05/30 11:03:57 johana 50 - * Implemented rs_send_xchar() by disabling the DMA and writing manually. 51 - * Added e100_disable_txdma_channel() and e100_enable_txdma_channel(). 52 - * Fixed rs_throttle() and rs_unthrottle() to properly call rs_send_xchar 53 - * instead of setting info->x_char and check the CRTSCTS flag before 54 - * controlling the rts pin. 55 - * 56 - * Revision 1.14 2003/04/09 08:12:44 pkj 57 - * Corrected typo changes made upstream. 58 - * 59 - * Revision 1.13 2003/04/09 05:20:47 starvik 60 - * Merge of Linux 2.5.67 61 - * 62 - * Revision 1.11 2003/01/22 06:48:37 starvik 63 - * Fixed warnings issued by GCC 3.2.1 64 - * 65 - * Revision 1.9 2002/12/13 09:07:47 starvik 66 - * Alert user that RX_TIMEOUT_TICKS==0 doesn't work 67 - * 68 - * Revision 1.8 2002/12/11 13:13:57 starvik 69 - * Added arch/ to v10 specific includes 70 - * Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer) 71 - * 72 - * Revision 1.7 2002/12/06 07:13:57 starvik 73 - * Corrected work queue stuff 74 - * Removed CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST 75 - * 76 - * Revision 1.6 2002/11/21 07:17:46 starvik 77 - * Change static inline to extern inline where otherwise outlined with gcc-3.2 78 - * 79 - * Revision 1.5 2002/11/14 15:59:49 starvik 80 - * Linux 2.5 port of the latest serial driver from 2.4. The work queue stuff 81 - * probably doesn't work yet. 82 - * 83 - * Revision 1.42 2002/11/05 09:08:47 johana 84 - * Better implementation of rs_stop() and rs_start() that uses the XOFF 85 - * register to start/stop transmission. 86 - * change_speed() also initilises XOFF register correctly so that 87 - * auto_xoff is enabled when IXON flag is set by user. 88 - * This gives fast XOFF response times. 89 - * 90 - * Revision 1.41 2002/11/04 18:40:57 johana 91 - * Implemented rs_stop() and rs_start(). 92 - * Simple tests using hwtestserial indicates that this should be enough 93 - * to make it work. 94 - * 95 - * Revision 1.40 2002/10/14 05:33:18 starvik 96 - * RS-485 uses fast timers even if SERIAL_FAST_TIMER is disabled 97 - * 98 - * Revision 1.39 2002/09/30 21:00:57 johana 99 - * Support for CONFIG_ETRAX_SERx_DTR_RI_DSR_CD_MIXED where the status and 100 - * control pins can be mixed between PA and PB. 101 - * If no serial port uses MIXED old solution is used 102 - * (saves a few bytes and cycles). 103 - * control_pins struct uses masks instead of bit numbers. 104 - * Corrected dummy values and polarity in line_info() so 105 - * /proc/tty/driver/serial is now correct. 106 - * (the E100_xxx_GET() macros is really active low - perhaps not obvious) 107 - * 108 - * Revision 1.38 2002/08/23 11:01:36 starvik 109 - * Check that serial port is enabled in all interrupt handlers to avoid 110 - * restarts of DMA channels not assigned to serial ports 111 - * 112 - * Revision 1.37 2002/08/13 13:02:37 bjornw 113 - * Removed some warnings because of unused code 114 - * 115 - * Revision 1.36 2002/08/08 12:50:01 starvik 116 - * Serial interrupt is shared with synchronous serial port driver 117 - * 118 - * Revision 1.35 2002/06/03 10:40:49 starvik 119 - * Increased RS-485 RTS toggle timer to 2 characters 120 - * 121 - * Revision 1.34 2002/05/28 18:59:36 johana 122 - * Whitespace and comment fixing to be more like etrax100ser.c 1.71. 123 - * 124 - * Revision 1.33 2002/05/28 17:55:43 johana 125 - * RS-485 uses FAST_TIMER if enabled, and starts a short (one char time) 126 - * timer from tranismit_chars (interrupt context). 127 - * The timer toggles RTS in interrupt context when expired giving minimum 128 - * latencies. 129 - * 130 - * Revision 1.32 2002/05/22 13:58:00 johana 131 - * Renamed rs_write() to raw_write() and made it inline. 132 - * New rs_write() handles RS-485 if configured and enabled 133 - * (moved code from e100_write_rs485()). 134 - * RS-485 ioctl's uses copy_from_user() instead of verify_area(). 135 - * 136 - * Revision 1.31 2002/04/22 11:20:03 johana 137 - * Updated copyright years. 138 - * 139 - * Revision 1.30 2002/04/22 09:39:12 johana 140 - * RS-485 support compiles. 141 - * 142 - * Revision 1.29 2002/01/14 16:10:01 pkj 143 - * Allocate the receive buffers dynamically. The static 4kB buffer was 144 - * too small for the peaks. This means that we can get rid of the extra 145 - * buffer and the copying to it. It also means we require less memory 146 - * under normal operations, but can use more when needed (there is a 147 - * cap at 64kB for safety reasons). If there is no memory available 148 - * we panic(), and die a horrible death... 149 - * 150 - * Revision 1.28 2001/12/18 15:04:53 johana 151 - * Cleaned up write_rs485() - now it works correctly without padding extra 152 - * char. 153 - * Added sane default initialisation of rs485. 154 - * Added #ifdef around dummy variables. 155 - * 156 - * Revision 1.27 2001/11/29 17:00:41 pkj 157 - * 2kB seems to be too small a buffer when using 921600 bps, 158 - * so increase it to 4kB (this was already done for the elinux 159 - * version of the serial driver). 160 - * 161 - * Revision 1.26 2001/11/19 14:20:41 pkj 162 - * Minor changes to comments and unused code. 163 - * 164 - * Revision 1.25 2001/11/12 20:03:43 pkj 165 - * Fixed compiler warnings. 166 - * 167 - * Revision 1.24 2001/11/12 15:10:05 pkj 168 - * Total redesign of the receiving part of the serial driver. 169 - * Uses eight chained descriptors to write to a 4kB buffer. 170 - * This data is then serialised into a 2kB buffer. From there it 171 - * is copied into the TTY's flip buffers when they become available. 172 - * A lot of copying, and the sizes of the buffers might need to be 173 - * tweaked, but all in all it should work better than the previous 174 - * version, without the need to modify the TTY code in any way. 175 - * Also note that erroneous bytes are now correctly marked in the 176 - * flag buffers (instead of always marking the first byte). 177 - * 178 - * Revision 1.23 2001/10/30 17:53:26 pkj 179 - * * Set info->uses_dma to 0 when a port is closed. 180 - * * Mark the timer1 interrupt as a fast one (SA_INTERRUPT). 181 - * * Call start_flush_timer() in start_receive() if 182 - * CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST is defined. 183 - * 184 - * Revision 1.22 2001/10/30 17:44:03 pkj 185 - * Use %lu for received and transmitted counters in line_info(). 186 - * 187 - * Revision 1.21 2001/10/30 17:40:34 pkj 188 - * Clean-up. The only change to functionality is that 189 - * CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS(=5) is used instead of 190 - * MAX_FLUSH_TIME(=8). 191 - * 192 - * Revision 1.20 2001/10/30 15:24:49 johana 193 - * Added char_time stuff from 2.0 driver. 194 - * 195 - * Revision 1.19 2001/10/30 15:23:03 johana 196 - * Merged with 1.13.2 branch + fixed indentation 197 - * and changed CONFIG_ETRAX100_XYS to CONFIG_ETRAX_XYZ 198 - * 199 - * Revision 1.18 2001/09/24 09:27:22 pkj 200 - * Completed ext_baud_table[] in cflag_to_baud() and cflag_to_etrax_baud(). 201 - * 202 - * Revision 1.17 2001/08/24 11:32:49 ronny 203 - * More fixes for the CONFIG_ETRAX_SERIAL_PORT0 define. 204 - * 205 - * Revision 1.16 2001/08/24 07:56:22 ronny 206 - * Added config ifdefs around ser0 irq requests. 207 - * 208 - * Revision 1.15 2001/08/16 09:10:31 bjarne 209 - * serial.c - corrected the initialization of rs_table, the wrong defines 210 - * where used. 211 - * Corrected a test in timed_flush_handler. 212 - * Changed configured to enabled. 213 - * serial.h - Changed configured to enabled. 214 - * 215 - * Revision 1.14 2001/08/15 07:31:23 bjarne 216 - * Introduced two new members to the e100_serial struct. 217 - * configured - Will be set to 1 if the port has been configured in .config 218 - * uses_dma - Should be set to 1 if the port uses DMA. Currently it is set 219 - * to 1 220 - * when a port is opened. This is used to limit the DMA interrupt 221 - * routines to only manipulate DMA channels actually used by the 222 - * serial driver. 223 - * 224 - * Revision 1.13.2.2 2001/10/17 13:57:13 starvik 225 - * Receiver was broken by the break fixes 226 - * 227 - * Revision 1.13.2.1 2001/07/20 13:57:39 ronny 228 - * Merge with new stuff from etrax100ser.c. Works but haven't checked stuff 229 - * like break handling. 230 - * 231 - * Revision 1.13 2001/05/09 12:40:31 johana 232 - * Use DMA_NBR and IRQ_NBR defines from dma.h and irq.h 233 - * 234 - * Revision 1.12 2001/04/19 12:23:07 bjornw 235 - * CONFIG_RS485 -> CONFIG_ETRAX_RS485 236 - * 237 - * Revision 1.11 2001/04/05 14:29:48 markusl 238 - * Updated according to review remarks i.e. 239 - * -Use correct types in port structure to avoid compiler warnings 240 - * -Try to use IO_* macros whenever possible 241 - * -Open should never return -EBUSY 242 - * 243 - * Revision 1.10 2001/03/05 13:14:07 bjornw 244 - * Another spelling fix 245 - * 246 - * Revision 1.9 2001/02/23 13:46:38 bjornw 247 - * Spellling check 248 - * 249 - * Revision 1.8 2001/01/23 14:56:35 markusl 250 - * Made use of ser1 optional 251 - * Needed by USB 252 - * 253 - * Revision 1.7 2001/01/19 16:14:48 perf 254 - * Added kernel options for serial ports 234. 255 - * Changed option names from CONFIG_ETRAX100_XYZ to CONFIG_ETRAX_XYZ. 256 - * 257 - * Revision 1.6 2000/11/22 16:36:09 bjornw 258 - * Please marketing by using the correct case when spelling Etrax. 259 - * 260 - * Revision 1.5 2000/11/21 16:43:37 bjornw 261 - * Fixed so it compiles under CONFIG_SVINTO_SIM 262 - * 263 - * Revision 1.4 2000/11/15 17:34:12 bjornw 264 - * Added a timeout timer for flushing input channels. The interrupt-based 265 - * fast flush system should be easy to merge with this later (works the same 266 - * way, only with an irq instead of a system timer_list) 267 - * 268 - * Revision 1.3 2000/11/13 17:19:57 bjornw 269 - * * Incredibly, this almost complete rewrite of serial.c worked (at least 270 - * for output) the first time. 271 - * 272 - * Items worth noticing: 273 - * 274 - * No Etrax100 port 1 workarounds (does only compile on 2.4 anyway now) 275 - * RS485 is not ported (why can't it be done in userspace as on x86 ?) 276 - * Statistics done through async_icount - if any more stats are needed, 277 - * that's the place to put them or in an arch-dep version of it. 278 - * timeout_interrupt and the other fast timeout stuff not ported yet 279 - * There be dragons in this 3k+ line driver 280 - * 281 - * Revision 1.2 2000/11/10 16:50:28 bjornw 282 - * First shot at a 2.4 port, does not compile totally yet 283 - * 284 - * Revision 1.1 2000/11/10 16:47:32 bjornw 285 - * Added verbatim copy of rev 1.49 etrax100ser.c from elinux 286 - * 287 - * Revision 1.49 2000/10/30 15:47:14 tobiasa 288 - * Changed version number. 289 - * 290 - * Revision 1.48 2000/10/25 11:02:43 johana 291 - * Changed %ul to %lu in printf's 292 - * 293 - * Revision 1.47 2000/10/18 15:06:53 pkj 294 - * Compile correctly with CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST and 295 - * CONFIG_ETRAX_SERIAL_PROC_ENTRY together. 296 - * Some clean-up of the /proc/serial file. 297 - * 298 - * Revision 1.46 2000/10/16 12:59:40 johana 299 - * Added CONFIG_ETRAX_SERIAL_PROC_ENTRY for statistics and debug info. 300 - * 301 - * Revision 1.45 2000/10/13 17:10:59 pkj 302 - * Do not flush DMAs while flipping TTY buffers. 303 - * 304 - * Revision 1.44 2000/10/13 16:34:29 pkj 305 - * Added a delay in ser_interrupt() for 2.3ms when an error is detected. 306 - * We do not know why this delay is required yet, but without it the 307 - * irmaflash program does not work (this was the program that needed 308 - * the ser_interrupt() to be needed in the first place). This should not 309 - * affect normal use of the serial ports. 310 - * 311 - * Revision 1.43 2000/10/13 16:30:44 pkj 312 - * New version of the fast flush of serial buffers code. This time 313 - * it is localized to the serial driver and uses a fast timer to 314 - * do the work. 315 - * 316 - * Revision 1.42 2000/10/13 14:54:26 bennyo 317 - * Fix for switching RTS when using rs485 318 - * 319 - * Revision 1.41 2000/10/12 11:43:44 pkj 320 - * Cleaned up a number of comments. 321 - * 322 - * Revision 1.40 2000/10/10 11:58:39 johana 323 - * Made RS485 support generic for all ports. 324 - * Toggle rts in interrupt if no delay wanted. 325 - * WARNING: No true transmitter empty check?? 326 - * Set d_wait bit when sending data so interrupt is delayed until 327 - * fifo flushed. (Fix tcdrain() problem) 328 - * 329 - * Revision 1.39 2000/10/04 16:08:02 bjornw 330 - * * Use virt_to_phys etc. for DMA addresses 331 - * * Removed CONFIG_FLUSH_DMA_FAST hacks 332 - * * Indentation fix 333 - * 334 - * Revision 1.38 2000/10/02 12:27:10 mattias 335 - * * added variable used when using fast flush on serial dma. 336 - * (CONFIG_FLUSH_DMA_FAST) 337 - * 338 - * Revision 1.37 2000/09/27 09:44:24 pkj 339 - * Uncomment definition of SERIAL_HANDLE_EARLY_ERRORS. 340 - * 341 - * Revision 1.36 2000/09/20 13:12:52 johana 342 - * Support for CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS: 343 - * Number of timer ticks between flush of receive fifo (1 tick = 10ms). 344 - * Try 0-3 for low latency applications. Approx 5 for high load 345 - * applications (e.g. PPP). Maybe this should be more adaptive some day... 346 - * 347 - * Revision 1.35 2000/09/20 10:36:08 johana 348 - * Typo in get_lsr_info() 349 - * 350 - * Revision 1.34 2000/09/20 10:29:59 johana 351 - * Let rs_chars_in_buffer() check fifo content as well. 352 - * get_lsr_info() might work now (not tested). 353 - * Easier to change the port to debug. 354 - * 355 - * Revision 1.33 2000/09/13 07:52:11 torbjore 356 - * Support RS485 357 - * 358 - * Revision 1.32 2000/08/31 14:45:37 bjornw 359 - * After sending a break we need to reset the transmit DMA channel 360 - * 361 - * Revision 1.31 2000/06/21 12:13:29 johana 362 - * Fixed wait for all chars sent when closing port. 363 - * (Used to always take 1 second!) 364 - * Added shadows for directions of status/ctrl signals. 365 - * 366 - * Revision 1.30 2000/05/29 16:27:55 bjornw 367 - * Simulator ifdef moved a bit 368 - * 369 - * Revision 1.29 2000/05/09 09:40:30 mattias 370 - * * Added description of dma registers used in timeout_interrupt 371 - * * Removed old code 372 - * 373 - * Revision 1.28 2000/05/08 16:38:58 mattias 374 - * * Bugfix for flushing fifo in timeout_interrupt 375 - * Problem occurs when bluetooth stack waits for a small number of bytes 376 - * containing an event acknowledging free buffers in bluetooth HW 377 - * As before, data was stuck in fifo until more data came on uart and 378 - * flushed it up to the stack. 379 - * 380 - * Revision 1.27 2000/05/02 09:52:28 jonasd 381 - * Added fix for peculiar etrax behaviour when eop is forced on an empty 382 - * fifo. This is used when flashing the IRMA chip. Disabled by default. 383 - * 384 - * Revision 1.26 2000/03/29 15:32:02 bjornw 385 - * 2.0.34 updates 386 - * 387 - * Revision 1.25 2000/02/16 16:59:36 bjornw 388 - * * Receive DMA directly into the flip-buffer, eliminating an intermediary 389 - * receive buffer and a memcpy. Will avoid some overruns. 390 - * * Error message on debug port if an overrun or flip buffer overrun occurs. 391 - * * Just use the first byte in the flag flip buffer for errors. 392 - * * Check for timeout on the serial ports only each 5/100 s, not 1/100. 393 - * 394 - * Revision 1.24 2000/02/09 18:02:28 bjornw 395 - * * Clear serial errors (overrun, framing, parity) correctly. Before, the 396 - * receiver would get stuck if an error occurred and we did not restart 397 - * the input DMA. 398 - * * Cosmetics (indentation, some code made into inlines) 399 - * * Some more debug options 400 - * * Actually shut down the serial port (DMA irq, DMA reset, receiver stop) 401 - * when the last open is closed. Corresponding fixes in startup(). 402 - * * rs_close() "tx FIFO wait" code moved into right place, bug & -> && fixed 403 - * and make a special case out of port 1 (R_DMA_CHx_STATUS is broken for that) 404 - * * e100_disable_rx/enable_rx just disables/enables the receiver, not RTS 405 - * 406 - * Revision 1.23 2000/01/24 17:46:19 johana 407 - * Wait for flush of DMA/FIFO when closing port. 408 - * 409 - * Revision 1.22 2000/01/20 18:10:23 johana 410 - * Added TIOCMGET ioctl to return modem status. 411 - * Implemented modem status/control that works with the extra signals 412 - * (DTR, DSR, RI,CD) as well. 413 - * 3 different modes supported: 414 - * ser0 on PB (Bundy), ser1 on PB (Lisa) and ser2 on PA (Bundy) 415 - * Fixed DEF_TX value that caused the serial transmitter pin (txd) to go to 0 when 416 - * closing the last filehandle, NASTY!. 417 - * Added break generation, not tested though! 418 - * Use IRQF_SHARED when request_irq() for ser2 and ser3 (shared with) par0 and par1. 419 - * You can't use them at the same time (yet..), but you can hopefully switch 420 - * between ser2/par0, ser3/par1 with the same kernel config. 421 - * Replaced some magic constants with defines 422 - * 423 7 * 424 8 */ 425 9 ··· 30 446 31 447 #include <asm/io.h> 32 448 #include <asm/irq.h> 449 + #include <asm/dma.h> 33 450 #include <asm/system.h> 34 451 #include <linux/delay.h> 35 452 ··· 39 454 /* non-arch dependent serial structures are in linux/serial.h */ 40 455 #include <linux/serial.h> 41 456 /* while we keep our own stuff (struct e100_serial) in a local .h file */ 42 - #include "serial.h" 457 + #include "crisv10.h" 43 458 #include <asm/fasttimer.h> 459 + #include <asm/arch/io_interface_mux.h> 44 460 45 461 #ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER 46 462 #ifndef CONFIG_ETRAX_FAST_TIMER ··· 89 503 be an error, break or similar. Used to be able to flash IRMA 90 504 from eLinux */ 91 505 #define SERIAL_HANDLE_EARLY_ERRORS 92 - 93 - /* Defined and used in n_tty.c, but we need it here as well */ 94 - #define TTY_THRESHOLD_THROTTLE 128 95 - 96 - /* Due to buffersizes and threshold values, our SERIAL_DESCR_BUF_SIZE 97 - * must not be to high or flow control won't work if we leave it to the tty 98 - * layer so we have our own throttling in flush_to_flip 99 - * TTY_FLIPBUF_SIZE=512, 100 - * TTY_THRESHOLD_THROTTLE/UNTHROTTLE=128 101 - * BUF_SIZE can't be > 128 102 - */ 103 - #define CRIS_BUF_SIZE 512 104 506 105 507 /* Currently 16 descriptors x 128 bytes = 2048 bytes */ 106 508 #define SERIAL_DESCR_BUF_SIZE 256 ··· 162 588 static void change_speed(struct e100_serial *info); 163 589 static void rs_throttle(struct tty_struct * tty); 164 590 static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 165 - static int rs_write(struct tty_struct * tty, int from_user, 166 - const unsigned char *buf, int count); 591 + static int rs_write(struct tty_struct *tty, 592 + const unsigned char *buf, int count); 167 593 #ifdef CONFIG_ETRAX_RS485 168 - static int e100_write_rs485(struct tty_struct * tty, int from_user, 169 - const unsigned char *buf, int count); 594 + static int e100_write_rs485(struct tty_struct *tty, 595 + const unsigned char *buf, int count); 170 596 #endif 171 - static int get_lsr_info(struct e100_serial * info, unsigned int *value); 597 + static int get_lsr_info(struct e100_serial *info, unsigned int *value); 172 598 173 599 174 600 #define DEF_BAUD 115200 /* 115.2 kbit/s */ ··· 253 679 .rx_ctrl = DEF_RX, 254 680 .tx_ctrl = DEF_TX, 255 681 .iseteop = 2, 682 + .dma_owner = dma_ser0, 683 + .io_if = if_serial_0, 256 684 #ifdef CONFIG_ETRAX_SERIAL_PORT0 257 685 .enabled = 1, 258 686 #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA6_OUT 259 687 .dma_out_enabled = 1, 688 + .dma_out_nbr = SER0_TX_DMA_NBR, 689 + .dma_out_irq_nbr = SER0_DMA_TX_IRQ_NBR, 690 + .dma_out_irq_flags = IRQF_DISABLED, 691 + .dma_out_irq_description = "serial 0 dma tr", 260 692 #else 261 693 .dma_out_enabled = 0, 694 + .dma_out_nbr = UINT_MAX, 695 + .dma_out_irq_nbr = 0, 696 + .dma_out_irq_flags = 0, 697 + .dma_out_irq_description = NULL, 262 698 #endif 263 699 #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA7_IN 264 700 .dma_in_enabled = 1, 701 + .dma_in_nbr = SER0_RX_DMA_NBR, 702 + .dma_in_irq_nbr = SER0_DMA_RX_IRQ_NBR, 703 + .dma_in_irq_flags = IRQF_DISABLED, 704 + .dma_in_irq_description = "serial 0 dma rec", 265 705 #else 266 - .dma_in_enabled = 0 706 + .dma_in_enabled = 0, 707 + .dma_in_nbr = UINT_MAX, 708 + .dma_in_irq_nbr = 0, 709 + .dma_in_irq_flags = 0, 710 + .dma_in_irq_description = NULL, 267 711 #endif 268 712 #else 269 713 .enabled = 0, 714 + .io_if_description = NULL, 270 715 .dma_out_enabled = 0, 271 716 .dma_in_enabled = 0 272 717 #endif ··· 307 714 .rx_ctrl = DEF_RX, 308 715 .tx_ctrl = DEF_TX, 309 716 .iseteop = 3, 717 + .dma_owner = dma_ser1, 718 + .io_if = if_serial_1, 310 719 #ifdef CONFIG_ETRAX_SERIAL_PORT1 311 720 .enabled = 1, 721 + .io_if_description = "ser1", 312 722 #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA8_OUT 313 723 .dma_out_enabled = 1, 724 + .dma_out_nbr = SER1_TX_DMA_NBR, 725 + .dma_out_irq_nbr = SER1_DMA_TX_IRQ_NBR, 726 + .dma_out_irq_flags = IRQF_DISABLED, 727 + .dma_out_irq_description = "serial 1 dma tr", 314 728 #else 315 729 .dma_out_enabled = 0, 730 + .dma_out_nbr = UINT_MAX, 731 + .dma_out_irq_nbr = 0, 732 + .dma_out_irq_flags = 0, 733 + .dma_out_irq_description = NULL, 316 734 #endif 317 735 #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA9_IN 318 736 .dma_in_enabled = 1, 737 + .dma_in_nbr = SER1_RX_DMA_NBR, 738 + .dma_in_irq_nbr = SER1_DMA_RX_IRQ_NBR, 739 + .dma_in_irq_flags = IRQF_DISABLED, 740 + .dma_in_irq_description = "serial 1 dma rec", 319 741 #else 320 - .dma_in_enabled = 0 742 + .dma_in_enabled = 0, 743 + .dma_in_enabled = 0, 744 + .dma_in_nbr = UINT_MAX, 745 + .dma_in_irq_nbr = 0, 746 + .dma_in_irq_flags = 0, 747 + .dma_in_irq_description = NULL, 321 748 #endif 322 749 #else 323 750 .enabled = 0, 751 + .io_if_description = NULL, 752 + .dma_in_irq_nbr = 0, 324 753 .dma_out_enabled = 0, 325 754 .dma_in_enabled = 0 326 755 #endif ··· 363 748 .rx_ctrl = DEF_RX, 364 749 .tx_ctrl = DEF_TX, 365 750 .iseteop = 0, 751 + .dma_owner = dma_ser2, 752 + .io_if = if_serial_2, 366 753 #ifdef CONFIG_ETRAX_SERIAL_PORT2 367 754 .enabled = 1, 755 + .io_if_description = "ser2", 368 756 #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA2_OUT 369 757 .dma_out_enabled = 1, 758 + .dma_out_nbr = SER2_TX_DMA_NBR, 759 + .dma_out_irq_nbr = SER2_DMA_TX_IRQ_NBR, 760 + .dma_out_irq_flags = IRQF_DISABLED, 761 + .dma_out_irq_description = "serial 2 dma tr", 370 762 #else 371 763 .dma_out_enabled = 0, 764 + .dma_out_nbr = UINT_MAX, 765 + .dma_out_irq_nbr = 0, 766 + .dma_out_irq_flags = 0, 767 + .dma_out_irq_description = NULL, 372 768 #endif 373 769 #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA3_IN 374 770 .dma_in_enabled = 1, 771 + .dma_in_nbr = SER2_RX_DMA_NBR, 772 + .dma_in_irq_nbr = SER2_DMA_RX_IRQ_NBR, 773 + .dma_in_irq_flags = IRQF_DISABLED, 774 + .dma_in_irq_description = "serial 2 dma rec", 375 775 #else 376 - .dma_in_enabled = 0 776 + .dma_in_enabled = 0, 777 + .dma_in_nbr = UINT_MAX, 778 + .dma_in_irq_nbr = 0, 779 + .dma_in_irq_flags = 0, 780 + .dma_in_irq_description = NULL, 377 781 #endif 378 782 #else 379 783 .enabled = 0, 784 + .io_if_description = NULL, 380 785 .dma_out_enabled = 0, 381 786 .dma_in_enabled = 0 382 787 #endif ··· 417 782 .rx_ctrl = DEF_RX, 418 783 .tx_ctrl = DEF_TX, 419 784 .iseteop = 1, 785 + .dma_owner = dma_ser3, 786 + .io_if = if_serial_3, 420 787 #ifdef CONFIG_ETRAX_SERIAL_PORT3 421 788 .enabled = 1, 789 + .io_if_description = "ser3", 422 790 #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA4_OUT 423 791 .dma_out_enabled = 1, 792 + .dma_out_nbr = SER3_TX_DMA_NBR, 793 + .dma_out_irq_nbr = SER3_DMA_TX_IRQ_NBR, 794 + .dma_out_irq_flags = IRQF_DISABLED, 795 + .dma_out_irq_description = "serial 3 dma tr", 424 796 #else 425 797 .dma_out_enabled = 0, 798 + .dma_out_nbr = UINT_MAX, 799 + .dma_out_irq_nbr = 0, 800 + .dma_out_irq_flags = 0, 801 + .dma_out_irq_description = NULL, 426 802 #endif 427 803 #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA5_IN 428 804 .dma_in_enabled = 1, 805 + .dma_in_nbr = SER3_RX_DMA_NBR, 806 + .dma_in_irq_nbr = SER3_DMA_RX_IRQ_NBR, 807 + .dma_in_irq_flags = IRQF_DISABLED, 808 + .dma_in_irq_description = "serial 3 dma rec", 429 809 #else 430 - .dma_in_enabled = 0 810 + .dma_in_enabled = 0, 811 + .dma_in_nbr = UINT_MAX, 812 + .dma_in_irq_nbr = 0, 813 + .dma_in_irq_flags = 0, 814 + .dma_in_irq_description = NULL 431 815 #endif 432 816 #else 433 817 .enabled = 0, 818 + .io_if_description = NULL, 434 819 .dma_out_enabled = 0, 435 820 .dma_in_enabled = 0 436 821 #endif ··· 1071 1416 { 1072 1417 unsigned long flags; 1073 1418 1074 - save_flags(flags); 1075 - cli(); 1419 + local_irq_save(flags); 1076 1420 *e100_modem_pins[info->line].dtr_shadow &= ~mask; 1077 1421 *e100_modem_pins[info->line].dtr_shadow |= (set ? 0 : mask); 1078 1422 *e100_modem_pins[info->line].dtr_port = *e100_modem_pins[info->line].dtr_shadow; 1079 - restore_flags(flags); 1423 + local_irq_restore(flags); 1080 1424 } 1081 1425 1082 1426 #ifdef SERIAL_DEBUG_IO ··· 1094 1440 { 1095 1441 #ifndef CONFIG_SVINTO_SIM 1096 1442 unsigned long flags; 1097 - save_flags(flags); 1098 - cli(); 1443 + local_irq_save(flags); 1099 1444 info->rx_ctrl &= ~E100_RTS_MASK; 1100 1445 info->rx_ctrl |= (set ? 0 : E100_RTS_MASK); /* RTS is active low */ 1101 1446 info->port[REG_REC_CTRL] = info->rx_ctrl; 1102 - restore_flags(flags); 1447 + local_irq_restore(flags); 1103 1448 #ifdef SERIAL_DEBUG_IO 1104 1449 printk("ser%i rts %i\n", info->line, set); 1105 1450 #endif ··· 1116 1463 unsigned char mask = e100_modem_pins[info->line].ri_mask; 1117 1464 unsigned long flags; 1118 1465 1119 - save_flags(flags); 1120 - cli(); 1466 + local_irq_save(flags); 1121 1467 *e100_modem_pins[info->line].ri_shadow &= ~mask; 1122 1468 *e100_modem_pins[info->line].ri_shadow |= (set ? 0 : mask); 1123 1469 *e100_modem_pins[info->line].ri_port = *e100_modem_pins[info->line].ri_shadow; 1124 - restore_flags(flags); 1470 + local_irq_restore(flags); 1125 1471 } 1126 1472 #endif 1127 1473 } ··· 1133 1481 unsigned char mask = e100_modem_pins[info->line].cd_mask; 1134 1482 unsigned long flags; 1135 1483 1136 - save_flags(flags); 1137 - cli(); 1484 + local_irq_save(flags); 1138 1485 *e100_modem_pins[info->line].cd_shadow &= ~mask; 1139 1486 *e100_modem_pins[info->line].cd_shadow |= (set ? 0 : mask); 1140 1487 *e100_modem_pins[info->line].cd_port = *e100_modem_pins[info->line].cd_shadow; 1141 - restore_flags(flags); 1488 + local_irq_restore(flags); 1142 1489 } 1143 1490 #endif 1144 1491 } ··· 1211 1560 /* Disable output DMA channel for the serial port in question 1212 1561 * ( set to something other then serialX) 1213 1562 */ 1214 - save_flags(flags); 1215 - cli(); 1563 + local_irq_save(flags); 1216 1564 DFLOW(DEBUG_LOG(info->line, "disable_txdma_channel %i\n", info->line)); 1217 1565 if (info->line == 0) { 1218 1566 if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma6)) == ··· 1239 1589 } 1240 1590 } 1241 1591 *R_GEN_CONFIG = genconfig_shadow; 1242 - restore_flags(flags); 1592 + local_irq_restore(flags); 1243 1593 } 1244 1594 1245 1595 ··· 1247 1597 { 1248 1598 unsigned long flags; 1249 1599 1250 - save_flags(flags); 1251 - cli(); 1600 + local_irq_save(flags); 1252 1601 DFLOW(DEBUG_LOG(info->line, "enable_txdma_channel %i\n", info->line)); 1253 1602 /* Enable output DMA channel for the serial port in question */ 1254 1603 if (info->line == 0) { ··· 1264 1615 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, serial3); 1265 1616 } 1266 1617 *R_GEN_CONFIG = genconfig_shadow; 1267 - restore_flags(flags); 1618 + local_irq_restore(flags); 1268 1619 } 1269 1620 1270 1621 static void e100_disable_rxdma_channel(struct e100_serial *info) ··· 1274 1625 /* Disable input DMA channel for the serial port in question 1275 1626 * ( set to something other then serialX) 1276 1627 */ 1277 - save_flags(flags); 1278 - cli(); 1628 + local_irq_save(flags); 1279 1629 if (info->line == 0) { 1280 1630 if ((genconfig_shadow & IO_MASK(R_GEN_CONFIG, dma7)) == 1281 1631 IO_STATE(R_GEN_CONFIG, dma7, serial0)) { ··· 1301 1653 } 1302 1654 } 1303 1655 *R_GEN_CONFIG = genconfig_shadow; 1304 - restore_flags(flags); 1656 + local_irq_restore(flags); 1305 1657 } 1306 1658 1307 1659 ··· 1309 1661 { 1310 1662 unsigned long flags; 1311 1663 1312 - save_flags(flags); 1313 - cli(); 1664 + local_irq_save(flags); 1314 1665 /* Enable input DMA channel for the serial port in question */ 1315 1666 if (info->line == 0) { 1316 1667 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma7); ··· 1325 1678 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, serial3); 1326 1679 } 1327 1680 *R_GEN_CONFIG = genconfig_shadow; 1328 - restore_flags(flags); 1681 + local_irq_restore(flags); 1329 1682 } 1330 1683 1331 1684 #ifdef SERIAL_HANDLE_EARLY_ERRORS ··· 1432 1785 } 1433 1786 1434 1787 static int 1435 - e100_write_rs485(struct tty_struct *tty, int from_user, 1788 + e100_write_rs485(struct tty_struct *tty, 1436 1789 const unsigned char *buf, int count) 1437 1790 { 1438 1791 struct e100_serial * info = (struct e100_serial *)tty->driver_data; ··· 1445 1798 */ 1446 1799 info->rs485.enabled = 1; 1447 1800 /* rs_write now deals with RS485 if enabled */ 1448 - count = rs_write(tty, from_user, buf, count); 1801 + count = rs_write(tty, buf, count); 1449 1802 info->rs485.enabled = old_enabled; 1450 1803 return count; 1451 1804 } ··· 1483 1836 unsigned long flags; 1484 1837 unsigned long xoff; 1485 1838 1486 - save_flags(flags); cli(); 1839 + local_irq_save(flags); 1487 1840 DFLOW(DEBUG_LOG(info->line, "XOFF rs_stop xmit %i\n", 1488 1841 CIRC_CNT(info->xmit.head, 1489 1842 info->xmit.tail,SERIAL_XMIT_SIZE))); ··· 1495 1848 } 1496 1849 1497 1850 *((unsigned long *)&info->port[REG_XOFF]) = xoff; 1498 - restore_flags(flags); 1851 + local_irq_restore(flags); 1499 1852 } 1500 1853 } 1501 1854 ··· 1507 1860 unsigned long flags; 1508 1861 unsigned long xoff; 1509 1862 1510 - save_flags(flags); cli(); 1863 + local_irq_save(flags); 1511 1864 DFLOW(DEBUG_LOG(info->line, "XOFF rs_start xmit %i\n", 1512 1865 CIRC_CNT(info->xmit.head, 1513 1866 info->xmit.tail,SERIAL_XMIT_SIZE))); ··· 1522 1875 info->xmit.head != info->xmit.tail && info->xmit.buf) 1523 1876 e100_enable_serial_tx_ready_irq(info); 1524 1877 1525 - restore_flags(flags); 1878 + local_irq_restore(flags); 1526 1879 } 1527 1880 } 1528 1881 ··· 1702 2055 static void flush_timeout_function(unsigned long data); 1703 2056 #define START_FLUSH_FAST_TIMER_TIME(info, string, usec) {\ 1704 2057 unsigned long timer_flags; \ 1705 - save_flags(timer_flags); \ 1706 - cli(); \ 2058 + local_irq_save(timer_flags); \ 1707 2059 if (fast_timers[info->line].function == NULL) { \ 1708 2060 serial_fast_timer_started++; \ 1709 2061 TIMERD(DEBUG_LOG(info->line, "start_timer %i ", info->line)); \ ··· 1716 2070 else { \ 1717 2071 TIMERD(DEBUG_LOG(info->line, "timer %i already running\n", info->line)); \ 1718 2072 } \ 1719 - restore_flags(timer_flags); \ 2073 + local_irq_restore(timer_flags); \ 1720 2074 } 1721 2075 #define START_FLUSH_FAST_TIMER(info, string) START_FLUSH_FAST_TIMER_TIME(info, string, info->flush_time_usec) 1722 2076 ··· 1745 2099 { 1746 2100 unsigned long flags; 1747 2101 1748 - save_flags(flags); 1749 - cli(); 2102 + local_irq_save(flags); 1750 2103 1751 2104 if (!info->first_recv_buffer) 1752 2105 info->first_recv_buffer = buffer; ··· 1758 2113 if (info->recv_cnt > info->max_recv_cnt) 1759 2114 info->max_recv_cnt = info->recv_cnt; 1760 2115 1761 - restore_flags(flags); 2116 + local_irq_restore(flags); 1762 2117 } 1763 2118 1764 2119 static int ··· 1778 2133 info->icount.rx++; 1779 2134 } else { 1780 2135 struct tty_struct *tty = info->tty; 1781 - *tty->flip.char_buf_ptr = data; 1782 - *tty->flip.flag_buf_ptr = flag; 1783 - tty->flip.flag_buf_ptr++; 1784 - tty->flip.char_buf_ptr++; 1785 - tty->flip.count++; 2136 + tty_insert_flip_char(tty, data, flag); 1786 2137 info->icount.rx++; 1787 2138 } 1788 2139 ··· 1963 2322 */ 1964 2323 return; 1965 2324 #endif 1966 - info->tty->flip.count = 0; 1967 2325 if (info->uses_dma_in) { 1968 2326 /* reset the input dma channel to be sure it works */ 1969 2327 ··· 2124 2484 { 2125 2485 struct tty_struct *tty; 2126 2486 struct etrax_recv_buffer *buffer; 2127 - unsigned int length; 2128 2487 unsigned long flags; 2129 - int max_flip_size; 2130 2488 2131 - if (!info->first_recv_buffer) 2132 - return; 2489 + local_irq_save(flags); 2490 + tty = info->tty; 2133 2491 2134 - save_flags(flags); 2135 - cli(); 2136 - 2137 - if (!(tty = info->tty)) { 2138 - restore_flags(flags); 2492 + if (!tty) { 2493 + local_irq_restore(flags); 2139 2494 return; 2140 2495 } 2141 2496 2142 2497 while ((buffer = info->first_recv_buffer) != NULL) { 2143 2498 unsigned int count = buffer->length; 2144 2499 2145 - count = tty_buffer_request_room(tty, count); 2146 - if (count == 0) /* Throttle ?? */ 2147 - break; 2148 - 2149 - if (count > 1) 2150 - tty_insert_flip_strings(tty, buffer->buffer, count - 1); 2151 - tty_insert_flip_char(tty, buffer->buffer[count-1], buffer->error); 2152 - 2500 + tty_insert_flip_string(tty, buffer->buffer, count); 2153 2501 info->recv_cnt -= count; 2154 2502 2155 2503 if (count == buffer->length) { ··· 2153 2525 if (!info->first_recv_buffer) 2154 2526 info->last_recv_buffer = NULL; 2155 2527 2156 - restore_flags(flags); 2528 + local_irq_restore(flags); 2157 2529 2158 - DFLIP( 2159 - if (1) { 2160 - DEBUG_LOG(info->line, "*** rxtot %i\n", info->icount.rx); 2161 - DEBUG_LOG(info->line, "ldisc %lu\n", tty->ldisc.chars_in_buffer(tty)); 2162 - DEBUG_LOG(info->line, "room %lu\n", tty->ldisc.receive_room(tty)); 2163 - } 2164 - 2165 - ); 2166 - 2167 - /* this includes a check for low-latency */ 2530 + /* This includes a check for low-latency */ 2168 2531 tty_flip_buffer_push(tty); 2169 2532 } 2170 2533 ··· 2298 2679 printk("!NO TTY!\n"); 2299 2680 return info; 2300 2681 } 2301 - if (tty->flip.count >= CRIS_BUF_SIZE - TTY_THRESHOLD_THROTTLE) { 2302 - /* check TTY_THROTTLED first so it indicates our state */ 2303 - if (!test_and_set_bit(TTY_THROTTLED, &tty->flags)) { 2304 - DFLOW(DEBUG_LOG(info->line, "rs_throttle flip.count: %i\n", tty->flip.count)); 2305 - rs_throttle(tty); 2306 - } 2307 - } 2308 - if (tty->flip.count >= CRIS_BUF_SIZE) { 2309 - DEBUG_LOG(info->line, "force FLIP! %i\n", tty->flip.count); 2310 - tty->flip.work.func((void *) tty); 2311 - if (tty->flip.count >= CRIS_BUF_SIZE) { 2312 - DEBUG_LOG(info->line, "FLIP FULL! %i\n", tty->flip.count); 2313 - return info; /* if TTY_DONT_FLIP is set */ 2314 - } 2315 - } 2682 + 2316 2683 /* Read data and status at the same time */ 2317 2684 data_read = *((unsigned long *)&info->port[REG_DATA_STATUS32]); 2318 2685 more_data: ··· 2351 2746 DEBUG_LOG(info->line, "EBRK %i\n", info->break_detected_cnt); 2352 2747 info->errorcode = ERRCODE_INSERT_BREAK; 2353 2748 } else { 2749 + unsigned char data = IO_EXTRACT(R_SERIAL0_READ, 2750 + data_in, data_read); 2751 + char flag = TTY_NORMAL; 2354 2752 if (info->errorcode == ERRCODE_INSERT_BREAK) { 2355 - info->icount.brk++; 2356 - *tty->flip.char_buf_ptr = 0; 2357 - *tty->flip.flag_buf_ptr = TTY_BREAK; 2358 - tty->flip.flag_buf_ptr++; 2359 - tty->flip.char_buf_ptr++; 2360 - tty->flip.count++; 2753 + struct tty_struct *tty = info->tty; 2754 + tty_insert_flip_char(tty, 0, flag); 2361 2755 info->icount.rx++; 2362 2756 } 2363 - *tty->flip.char_buf_ptr = IO_EXTRACT(R_SERIAL0_READ, data_in, data_read); 2364 2757 2365 2758 if (data_read & IO_MASK(R_SERIAL0_READ, par_err)) { 2366 2759 info->icount.parity++; 2367 - *tty->flip.flag_buf_ptr = TTY_PARITY; 2760 + flag = TTY_PARITY; 2368 2761 } else if (data_read & IO_MASK(R_SERIAL0_READ, overrun)) { 2369 2762 info->icount.overrun++; 2370 - *tty->flip.flag_buf_ptr = TTY_OVERRUN; 2763 + flag = TTY_OVERRUN; 2371 2764 } else if (data_read & IO_MASK(R_SERIAL0_READ, framing_err)) { 2372 2765 info->icount.frame++; 2373 - *tty->flip.flag_buf_ptr = TTY_FRAME; 2766 + flag = TTY_FRAME; 2374 2767 } 2768 + tty_insert_flip_char(tty, data, flag); 2375 2769 info->errorcode = 0; 2376 2770 } 2377 2771 info->break_detected_cnt = 0; ··· 2386 2782 log_int(rdpc(), 0, 0); 2387 2783 } 2388 2784 ); 2389 - *tty->flip.char_buf_ptr = IO_EXTRACT(R_SERIAL0_READ, data_in, data_read); 2390 - *tty->flip.flag_buf_ptr = 0; 2785 + tty_insert_flip_char(tty, 2786 + IO_EXTRACT(R_SERIAL0_READ, data_in, data_read), 2787 + TTY_NORMAL); 2391 2788 } else { 2392 2789 DEBUG_LOG(info->line, "ser_rx int but no data_avail %08lX\n", data_read); 2393 2790 } 2394 2791 2395 2792 2396 - tty->flip.flag_buf_ptr++; 2397 - tty->flip.char_buf_ptr++; 2398 - tty->flip.count++; 2399 2793 info->icount.rx++; 2400 2794 data_read = *((unsigned long *)&info->port[REG_DATA_STATUS32]); 2401 2795 if (data_read & IO_MASK(R_SERIAL0_READ, data_avail)) { ··· 2531 2929 if (info->x_char) { 2532 2930 unsigned char rstat; 2533 2931 DFLOW(DEBUG_LOG(info->line, "tx_int: xchar 0x%02X\n", info->x_char)); 2534 - save_flags(flags); cli(); 2932 + local_irq_save(flags); 2535 2933 rstat = info->port[REG_STATUS]; 2536 2934 DFLOW(DEBUG_LOG(info->line, "stat %x\n", rstat)); 2537 2935 ··· 2540 2938 info->x_char = 0; 2541 2939 /* We must enable since it is disabled in ser_interrupt */ 2542 2940 e100_enable_serial_tx_ready_irq(info); 2543 - restore_flags(flags); 2941 + local_irq_restore(flags); 2544 2942 return; 2545 2943 } 2546 2944 if (info->uses_dma_out) { ··· 2548 2946 int i; 2549 2947 /* We only use normal tx interrupt when sending x_char */ 2550 2948 DFLOW(DEBUG_LOG(info->line, "tx_int: xchar sent\n", 0)); 2551 - save_flags(flags); cli(); 2949 + local_irq_save(flags); 2552 2950 rstat = info->port[REG_STATUS]; 2553 2951 DFLOW(DEBUG_LOG(info->line, "stat %x\n", rstat)); 2554 2952 e100_disable_serial_tx_ready_irq(info); ··· 2561 2959 nop(); 2562 2960 2563 2961 *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, continue); 2564 - restore_flags(flags); 2962 + local_irq_restore(flags); 2565 2963 return; 2566 2964 } 2567 2965 /* Normal char-by-char interrupt */ ··· 2575 2973 } 2576 2974 DINTR2(DEBUG_LOG(info->line, "tx_int %c\n", info->xmit.buf[info->xmit.tail])); 2577 2975 /* Send a byte, rs485 timing is critical so turn of ints */ 2578 - save_flags(flags); cli(); 2976 + local_irq_save(flags); 2579 2977 info->port[REG_TR_DATA] = info->xmit.buf[info->xmit.tail]; 2580 2978 info->xmit.tail = (info->xmit.tail + 1) & (SERIAL_XMIT_SIZE-1); 2581 2979 info->icount.tx++; ··· 2599 2997 /* We must enable since it is disabled in ser_interrupt */ 2600 2998 e100_enable_serial_tx_ready_irq(info); 2601 2999 } 2602 - restore_flags(flags); 3000 + local_irq_restore(flags); 2603 3001 2604 3002 if (CIRC_CNT(info->xmit.head, 2605 3003 info->xmit.tail, ··· 2624 3022 int handled = 0; 2625 3023 static volatile unsigned long reentered_ready_mask = 0; 2626 3024 2627 - save_flags(flags); cli(); 3025 + local_irq_save(flags); 2628 3026 irq_mask1_rd = *R_IRQ_MASK1_RD; 2629 3027 /* First handle all rx interrupts with ints disabled */ 2630 3028 info = rs_table; ··· 2669 3067 /* Unblock the serial interrupt */ 2670 3068 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set); 2671 3069 2672 - sti(); 3070 + local_irq_enable(); 2673 3071 ready_mask = (1 << (8+1+2*0)); /* ser0 tr_ready */ 2674 3072 info = rs_table; 2675 3073 for (i = 0; i < NR_PORTS; i++) { ··· 2682 3080 ready_mask <<= 2; 2683 3081 } 2684 3082 /* handle_ser_tx_interrupt enables tr_ready interrupts */ 2685 - cli(); 3083 + local_irq_disable(); 2686 3084 /* Handle reentered TX interrupt */ 2687 3085 irq_mask1_rd = reentered_ready_mask; 2688 3086 } 2689 - cli(); 3087 + local_irq_disable(); 2690 3088 tx_started = 0; 2691 3089 } else { 2692 3090 unsigned long ready_mask; ··· 2702 3100 } 2703 3101 } 2704 3102 2705 - restore_flags(flags); 3103 + local_irq_restore(flags); 2706 3104 return IRQ_RETVAL(handled); 2707 3105 } /* ser_interrupt */ 2708 3106 #endif ··· 2723 3121 * them using rs_sched_event(), and they get done here. 2724 3122 */ 2725 3123 static void 2726 - do_softint(void *private_) 3124 + do_softint(struct work_struct *work) 2727 3125 { 2728 - struct e100_serial *info = (struct e100_serial *) private_; 3126 + struct e100_serial *info; 2729 3127 struct tty_struct *tty; 3128 + 3129 + info = container_of(work, struct e100_serial, work); 2730 3130 2731 3131 tty = info->tty; 2732 3132 if (!tty) ··· 2749 3145 if (!xmit_page) 2750 3146 return -ENOMEM; 2751 3147 2752 - save_flags(flags); 2753 - cli(); 3148 + local_irq_save(flags); 2754 3149 2755 3150 /* if it was already initialized, skip this */ 2756 3151 2757 3152 if (info->flags & ASYNC_INITIALIZED) { 2758 - restore_flags(flags); 3153 + local_irq_restore(flags); 2759 3154 free_page(xmit_page); 2760 3155 return 0; 2761 3156 } ··· 2880 3277 2881 3278 info->flags |= ASYNC_INITIALIZED; 2882 3279 2883 - restore_flags(flags); 3280 + local_irq_restore(flags); 2884 3281 return 0; 2885 3282 } 2886 3283 ··· 2931 3328 info->irq); 2932 3329 #endif 2933 3330 2934 - save_flags(flags); 2935 - cli(); /* Disable interrupts */ 3331 + local_irq_save(flags); 2936 3332 2937 3333 if (info->xmit.buf) { 2938 3334 free_page((unsigned long)info->xmit.buf); ··· 2955 3353 set_bit(TTY_IO_ERROR, &info->tty->flags); 2956 3354 2957 3355 info->flags &= ~ASYNC_INITIALIZED; 2958 - restore_flags(flags); 3356 + local_irq_restore(flags); 2959 3357 } 2960 3358 2961 3359 ··· 3013 3411 DBAUD(printk("using external baudrate: %lu\n", CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8)); 3014 3412 info->baud = CONFIG_ETRAX_EXTERN_PB6CLK_FREQ/8; 3015 3413 } 3016 - } 3017 3414 #endif 3018 3415 else 3019 3416 { ··· 3046 3445 3047 3446 #ifndef CONFIG_SVINTO_SIM 3048 3447 /* start with default settings and then fill in changes */ 3049 - save_flags(flags); 3050 - cli(); 3448 + local_irq_save(flags); 3051 3449 /* 8 bit, no/even parity */ 3052 3450 info->rx_ctrl &= ~(IO_MASK(R_SERIAL0_REC_CTRL, rec_bitnr) | 3053 3451 IO_MASK(R_SERIAL0_REC_CTRL, rec_par_en) | ··· 3110 3510 } 3111 3511 3112 3512 *((unsigned long *)&info->port[REG_XOFF]) = xoff; 3113 - restore_flags(flags); 3513 + local_irq_restore(flags); 3114 3514 #endif /* !CONFIG_SVINTO_SIM */ 3115 3515 3116 3516 update_char_time(info); ··· 3138 3538 3139 3539 /* this protection might not exactly be necessary here */ 3140 3540 3141 - save_flags(flags); 3142 - cli(); 3541 + local_irq_save(flags); 3143 3542 start_transmit(info); 3144 - restore_flags(flags); 3543 + local_irq_restore(flags); 3145 3544 } 3146 3545 3147 - static int rs_raw_write(struct tty_struct * tty, int from_user, 3546 + static int rs_raw_write(struct tty_struct *tty, 3148 3547 const unsigned char *buf, int count) 3149 3548 { 3150 3549 int c, ret = 0; ··· 3166 3567 SIMCOUT(buf, count); 3167 3568 return count; 3168 3569 #endif 3169 - save_flags(flags); 3570 + local_save_flags(flags); 3170 3571 DFLOW(DEBUG_LOG(info->line, "write count %i ", count)); 3171 3572 DFLOW(DEBUG_LOG(info->line, "ldisc %i\n", tty->ldisc.chars_in_buffer(tty))); 3172 3573 3173 3574 3174 - /* the cli/restore_flags pairs below are needed because the 3175 - * DMA interrupt handler moves the info->xmit values. the memcpy 3176 - * needs to be in the critical region unfortunately, because we 3177 - * need to read xmit values, memcpy, write xmit values in one 3178 - * atomic operation... this could perhaps be avoided by more clever 3179 - * design. 3575 + /* The local_irq_disable/restore_flags pairs below are needed 3576 + * because the DMA interrupt handler moves the info->xmit values. 3577 + * the memcpy needs to be in the critical region unfortunately, 3578 + * because we need to read xmit values, memcpy, write xmit values 3579 + * in one atomic operation... this could perhaps be avoided by 3580 + * more clever design. 3180 3581 */ 3181 - if (from_user) { 3182 - mutex_lock(&tmp_buf_mutex); 3183 - while (1) { 3184 - int c1; 3185 - c = CIRC_SPACE_TO_END(info->xmit.head, 3186 - info->xmit.tail, 3187 - SERIAL_XMIT_SIZE); 3188 - if (count < c) 3189 - c = count; 3190 - if (c <= 0) 3191 - break; 3192 - 3193 - c -= copy_from_user(tmp_buf, buf, c); 3194 - if (!c) { 3195 - if (!ret) 3196 - ret = -EFAULT; 3197 - break; 3198 - } 3199 - cli(); 3200 - c1 = CIRC_SPACE_TO_END(info->xmit.head, 3201 - info->xmit.tail, 3202 - SERIAL_XMIT_SIZE); 3203 - if (c1 < c) 3204 - c = c1; 3205 - memcpy(info->xmit.buf + info->xmit.head, tmp_buf, c); 3206 - info->xmit.head = ((info->xmit.head + c) & 3207 - (SERIAL_XMIT_SIZE-1)); 3208 - restore_flags(flags); 3209 - buf += c; 3210 - count -= c; 3211 - ret += c; 3212 - } 3213 - mutex_unlock(&tmp_buf_mutex); 3214 - } else { 3215 - cli(); 3582 + local_irq_disable(); 3216 3583 while (count) { 3217 3584 c = CIRC_SPACE_TO_END(info->xmit.head, 3218 3585 info->xmit.tail, ··· 3196 3631 count -= c; 3197 3632 ret += c; 3198 3633 } 3199 - restore_flags(flags); 3200 - } 3634 + local_irq_restore(flags); 3201 3635 3202 3636 /* enable transmitter if not running, unless the tty is stopped 3203 3637 * this does not need IRQ protection since if tr_running == 0 ··· 3215 3651 } /* raw_raw_write() */ 3216 3652 3217 3653 static int 3218 - rs_write(struct tty_struct * tty, int from_user, 3654 + rs_write(struct tty_struct *tty, 3219 3655 const unsigned char *buf, int count) 3220 3656 { 3221 3657 #if defined(CONFIG_ETRAX_RS485) ··· 3242 3678 } 3243 3679 #endif /* CONFIG_ETRAX_RS485 */ 3244 3680 3245 - count = rs_raw_write(tty, from_user, buf, count); 3681 + count = rs_raw_write(tty, buf, count); 3246 3682 3247 3683 #if defined(CONFIG_ETRAX_RS485) 3248 3684 if (info->rs485.enabled) ··· 3310 3746 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 3311 3747 unsigned long flags; 3312 3748 3313 - save_flags(flags); 3314 - cli(); 3749 + local_irq_save(flags); 3315 3750 info->xmit.head = info->xmit.tail = 0; 3316 - restore_flags(flags); 3751 + local_irq_restore(flags); 3317 3752 3318 3753 tty_wakeup(tty); 3319 3754 } ··· 3330 3767 { 3331 3768 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 3332 3769 unsigned long flags; 3333 - save_flags(flags); cli(); 3770 + local_irq_save(flags); 3334 3771 if (info->uses_dma_out) { 3335 3772 /* Put the DMA on hold and disable the channel */ 3336 3773 *info->ocmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, hold); ··· 3347 3784 DFLOW(DEBUG_LOG(info->line, "rs_send_xchar 0x%02X\n", ch)); 3348 3785 info->x_char = ch; 3349 3786 e100_enable_serial_tx_ready_irq(info); 3350 - restore_flags(flags); 3787 + local_irq_restore(flags); 3351 3788 } 3352 3789 3353 3790 /* ··· 3559 3996 } 3560 3997 #endif 3561 3998 3562 - static int 3563 - get_modem_info(struct e100_serial * info, unsigned int *value) 3999 + static void 4000 + rs_break(struct tty_struct *tty, int break_state) 3564 4001 { 3565 - unsigned int result; 3566 - /* Polarity isn't verified */ 3567 - #if 0 /*def SERIAL_DEBUG_IO */ 4002 + struct e100_serial *info = (struct e100_serial *)tty->driver_data; 4003 + unsigned long flags; 3568 4004 3569 - printk("get_modem_info: RTS: %i DTR: %i CD: %i RI: %i DSR: %i CTS: %i\n", 3570 - E100_RTS_GET(info), 3571 - E100_DTR_GET(info), 3572 - E100_CD_GET(info), 3573 - E100_RI_GET(info), 3574 - E100_DSR_GET(info), 3575 - E100_CTS_GET(info)); 3576 - #endif 4005 + if (!info->port) 4006 + return; 4007 + 4008 + local_irq_save(flags); 4009 + if (break_state == -1) { 4010 + /* Go to manual mode and set the txd pin to 0 */ 4011 + /* Clear bit 7 (txd) and 6 (tr_enable) */ 4012 + info->tx_ctrl &= 0x3F; 4013 + } else { 4014 + /* Set bit 7 (txd) and 6 (tr_enable) */ 4015 + info->tx_ctrl |= (0x80 | 0x40); 4016 + } 4017 + info->port[REG_TR_CTRL] = info->tx_ctrl; 4018 + local_irq_restore(flags); 4019 + } 4020 + 4021 + static int 4022 + rs_tiocmset(struct tty_struct *tty, struct file *file, 4023 + unsigned int set, unsigned int clear) 4024 + { 4025 + struct e100_serial *info = (struct e100_serial *)tty->driver_data; 4026 + 4027 + if (clear & TIOCM_RTS) 4028 + e100_rts(info, 0); 4029 + if (clear & TIOCM_DTR) 4030 + e100_dtr(info, 0); 4031 + /* Handle FEMALE behaviour */ 4032 + if (clear & TIOCM_RI) 4033 + e100_ri_out(info, 0); 4034 + if (clear & TIOCM_CD) 4035 + e100_cd_out(info, 0); 4036 + 4037 + if (set & TIOCM_RTS) 4038 + e100_rts(info, 1); 4039 + if (set & TIOCM_DTR) 4040 + e100_dtr(info, 1); 4041 + /* Handle FEMALE behaviour */ 4042 + if (set & TIOCM_RI) 4043 + e100_ri_out(info, 1); 4044 + if (set & TIOCM_CD) 4045 + e100_cd_out(info, 1); 4046 + return 0; 4047 + } 4048 + 4049 + static int 4050 + rs_tiocmget(struct tty_struct *tty, struct file *file) 4051 + { 4052 + struct e100_serial *info = (struct e100_serial *)tty->driver_data; 4053 + unsigned int result; 3577 4054 3578 4055 result = 3579 4056 (!E100_RTS_GET(info) ? TIOCM_RTS : 0) ··· 3624 4021 | (!E100_CTS_GET(info) ? TIOCM_CTS : 0); 3625 4022 3626 4023 #ifdef SERIAL_DEBUG_IO 3627 - printk("e100ser: modem state: %i 0x%08X\n", result, result); 4024 + printk(KERN_DEBUG "ser%i: modem state: %i 0x%08X\n", 4025 + info->line, result, result); 3628 4026 { 3629 4027 char s[100]; 3630 4028 3631 4029 get_control_state_str(result, s); 3632 - printk("state: %s\n", s); 4030 + printk(KERN_DEBUG "state: %s\n", s); 3633 4031 } 3634 4032 #endif 3635 - if (copy_to_user(value, &result, sizeof(int))) 3636 - return -EFAULT; 3637 - return 0; 4033 + return result; 4034 + 3638 4035 } 3639 4036 3640 - 3641 - static int 3642 - set_modem_info(struct e100_serial * info, unsigned int cmd, 3643 - unsigned int *value) 3644 - { 3645 - unsigned int arg; 3646 - 3647 - if (copy_from_user(&arg, value, sizeof(int))) 3648 - return -EFAULT; 3649 - 3650 - switch (cmd) { 3651 - case TIOCMBIS: 3652 - if (arg & TIOCM_RTS) { 3653 - e100_rts(info, 1); 3654 - } 3655 - if (arg & TIOCM_DTR) { 3656 - e100_dtr(info, 1); 3657 - } 3658 - /* Handle FEMALE behaviour */ 3659 - if (arg & TIOCM_RI) { 3660 - e100_ri_out(info, 1); 3661 - } 3662 - if (arg & TIOCM_CD) { 3663 - e100_cd_out(info, 1); 3664 - } 3665 - break; 3666 - case TIOCMBIC: 3667 - if (arg & TIOCM_RTS) { 3668 - e100_rts(info, 0); 3669 - } 3670 - if (arg & TIOCM_DTR) { 3671 - e100_dtr(info, 0); 3672 - } 3673 - /* Handle FEMALE behaviour */ 3674 - if (arg & TIOCM_RI) { 3675 - e100_ri_out(info, 0); 3676 - } 3677 - if (arg & TIOCM_CD) { 3678 - e100_cd_out(info, 0); 3679 - } 3680 - break; 3681 - case TIOCMSET: 3682 - e100_rts(info, arg & TIOCM_RTS); 3683 - e100_dtr(info, arg & TIOCM_DTR); 3684 - /* Handle FEMALE behaviour */ 3685 - e100_ri_out(info, arg & TIOCM_RI); 3686 - e100_cd_out(info, arg & TIOCM_CD); 3687 - break; 3688 - default: 3689 - return -EINVAL; 3690 - } 3691 - return 0; 3692 - } 3693 - 3694 - 3695 - static void 3696 - rs_break(struct tty_struct *tty, int break_state) 3697 - { 3698 - struct e100_serial * info = (struct e100_serial *)tty->driver_data; 3699 - unsigned long flags; 3700 - 3701 - if (!info->port) 3702 - return; 3703 - 3704 - save_flags(flags); 3705 - cli(); 3706 - if (break_state == -1) { 3707 - /* Go to manual mode and set the txd pin to 0 */ 3708 - info->tx_ctrl &= 0x3F; /* Clear bit 7 (txd) and 6 (tr_enable) */ 3709 - } else { 3710 - info->tx_ctrl |= (0x80 | 0x40); /* Set bit 7 (txd) and 6 (tr_enable) */ 3711 - } 3712 - info->port[REG_TR_CTRL] = info->tx_ctrl; 3713 - restore_flags(flags); 3714 - } 3715 4037 3716 4038 static int 3717 4039 rs_ioctl(struct tty_struct *tty, struct file * file, ··· 3652 4124 } 3653 4125 3654 4126 switch (cmd) { 3655 - case TIOCMGET: 3656 - return get_modem_info(info, (unsigned int *) arg); 3657 - case TIOCMBIS: 3658 - case TIOCMBIC: 3659 - case TIOCMSET: 3660 - return set_modem_info(info, cmd, (unsigned int *) arg); 3661 - case TIOCGSERIAL: 3662 - return get_serial_info(info, 3663 - (struct serial_struct *) arg); 3664 - case TIOCSSERIAL: 3665 - return set_serial_info(info, 3666 - (struct serial_struct *) arg); 3667 - case TIOCSERGETLSR: /* Get line status register */ 3668 - return get_lsr_info(info, (unsigned int *) arg); 4127 + case TIOCGSERIAL: 4128 + return get_serial_info(info, 4129 + (struct serial_struct *) arg); 4130 + case TIOCSSERIAL: 4131 + return set_serial_info(info, 4132 + (struct serial_struct *) arg); 4133 + case TIOCSERGETLSR: /* Get line status register */ 4134 + return get_lsr_info(info, (unsigned int *) arg); 3669 4135 3670 - case TIOCSERGSTRUCT: 3671 - if (copy_to_user((struct e100_serial *) arg, 3672 - info, sizeof(struct e100_serial))) 3673 - return -EFAULT; 3674 - return 0; 4136 + case TIOCSERGSTRUCT: 4137 + if (copy_to_user((struct e100_serial *) arg, 4138 + info, sizeof(struct e100_serial))) 4139 + return -EFAULT; 4140 + return 0; 3675 4141 3676 4142 #if defined(CONFIG_ETRAX_RS485) 3677 - case TIOCSERSETRS485: 3678 - { 3679 - struct rs485_control rs485ctrl; 3680 - if (copy_from_user(&rs485ctrl, (struct rs485_control*)arg, sizeof(rs485ctrl))) 3681 - return -EFAULT; 4143 + case TIOCSERSETRS485: 4144 + { 4145 + struct rs485_control rs485ctrl; 4146 + if (copy_from_user(&rs485ctrl, (struct rs485_control *)arg, 4147 + sizeof(rs485ctrl))) 4148 + return -EFAULT; 3682 4149 3683 - return e100_enable_rs485(tty, &rs485ctrl); 3684 - } 4150 + return e100_enable_rs485(tty, &rs485ctrl); 4151 + } 3685 4152 3686 - case TIOCSERWRRS485: 3687 - { 3688 - struct rs485_write rs485wr; 3689 - if (copy_from_user(&rs485wr, (struct rs485_write*)arg, sizeof(rs485wr))) 3690 - return -EFAULT; 4153 + case TIOCSERWRRS485: 4154 + { 4155 + struct rs485_write rs485wr; 4156 + if (copy_from_user(&rs485wr, (struct rs485_write *)arg, 4157 + sizeof(rs485wr))) 4158 + return -EFAULT; 3691 4159 3692 - return e100_write_rs485(tty, 1, rs485wr.outc, rs485wr.outc_size); 3693 - } 4160 + return e100_write_rs485(tty, rs485wr.outc, rs485wr.outc_size); 4161 + } 3694 4162 #endif 3695 4163 3696 - default: 3697 - return -ENOIOCTLCMD; 4164 + default: 4165 + return -ENOIOCTLCMD; 3698 4166 } 3699 4167 return 0; 3700 4168 } ··· 3715 4191 3716 4192 } 3717 4193 3718 - /* In debugport.c - register a console write function that uses the normal 3719 - * serial driver 3720 - */ 3721 - typedef int (*debugport_write_function)(int i, const char *buf, unsigned int len); 3722 - 3723 - extern debugport_write_function debug_write_function; 3724 - 3725 - static int rs_debug_write_function(int i, const char *buf, unsigned int len) 3726 - { 3727 - int cnt; 3728 - int written = 0; 3729 - struct tty_struct *tty; 3730 - static int recurse_cnt = 0; 3731 - 3732 - tty = rs_table[i].tty; 3733 - if (tty) { 3734 - unsigned long flags; 3735 - if (recurse_cnt > 5) /* We skip this debug output */ 3736 - return 1; 3737 - 3738 - local_irq_save(flags); 3739 - recurse_cnt++; 3740 - local_irq_restore(flags); 3741 - do { 3742 - cnt = rs_write(tty, 0, buf + written, len); 3743 - if (cnt >= 0) { 3744 - written += cnt; 3745 - buf += cnt; 3746 - len -= cnt; 3747 - } else 3748 - len = cnt; 3749 - } while(len > 0); 3750 - local_irq_save(flags); 3751 - recurse_cnt--; 3752 - local_irq_restore(flags); 3753 - return 1; 3754 - } 3755 - return 0; 3756 - } 3757 - 3758 4194 /* 3759 4195 * ------------------------------------------------------------ 3760 4196 * rs_close() ··· 3736 4252 3737 4253 /* interrupts are disabled for this entire function */ 3738 4254 3739 - save_flags(flags); 3740 - cli(); 4255 + local_irq_save(flags); 3741 4256 3742 4257 if (tty_hung_up_p(filp)) { 3743 - restore_flags(flags); 4258 + local_irq_restore(flags); 3744 4259 return; 3745 4260 } 3746 4261 ··· 3766 4283 info->count = 0; 3767 4284 } 3768 4285 if (info->count) { 3769 - restore_flags(flags); 4286 + local_irq_restore(flags); 3770 4287 return; 3771 4288 } 3772 4289 info->flags |= ASYNC_CLOSING; ··· 3820 4337 } 3821 4338 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 3822 4339 wake_up_interruptible(&info->close_wait); 3823 - restore_flags(flags); 4340 + local_irq_restore(flags); 3824 4341 3825 4342 /* port closed */ 3826 4343 ··· 3842 4359 #endif 3843 4360 } 3844 4361 #endif 4362 + 4363 + /* 4364 + * Release any allocated DMA irq's. 4365 + */ 4366 + if (info->dma_in_enabled) { 4367 + free_irq(info->dma_in_irq_nbr, info); 4368 + cris_free_dma(info->dma_in_nbr, info->dma_in_irq_description); 4369 + info->uses_dma_in = 0; 4370 + #ifdef SERIAL_DEBUG_OPEN 4371 + printk(KERN_DEBUG "DMA irq '%s' freed\n", 4372 + info->dma_in_irq_description); 4373 + #endif 4374 + } 4375 + if (info->dma_out_enabled) { 4376 + free_irq(info->dma_out_irq_nbr, info); 4377 + cris_free_dma(info->dma_out_nbr, info->dma_out_irq_description); 4378 + info->uses_dma_out = 0; 4379 + #ifdef SERIAL_DEBUG_OPEN 4380 + printk(KERN_DEBUG "DMA irq '%s' freed\n", 4381 + info->dma_out_irq_description); 4382 + #endif 4383 + } 3845 4384 } 3846 4385 3847 4386 /* ··· 3938 4433 */ 3939 4434 if (tty_hung_up_p(filp) || 3940 4435 (info->flags & ASYNC_CLOSING)) { 3941 - if (info->flags & ASYNC_CLOSING) 3942 - interruptible_sleep_on(&info->close_wait); 4436 + wait_event_interruptible(info->close_wait, 4437 + !(info->flags & ASYNC_CLOSING)); 3943 4438 #ifdef SERIAL_DO_RESTART 3944 4439 if (info->flags & ASYNC_HUP_NOTIFY) 3945 4440 return -EAGAIN; ··· 3977 4472 printk("block_til_ready before block: ttyS%d, count = %d\n", 3978 4473 info->line, info->count); 3979 4474 #endif 3980 - save_flags(flags); 3981 - cli(); 4475 + local_irq_save(flags); 3982 4476 if (!tty_hung_up_p(filp)) { 3983 4477 extra_count++; 3984 4478 info->count--; 3985 4479 } 3986 - restore_flags(flags); 4480 + local_irq_restore(flags); 3987 4481 info->blocked_open++; 3988 4482 while (1) { 3989 - save_flags(flags); 3990 - cli(); 4483 + local_irq_save(flags); 3991 4484 /* assert RTS and DTR */ 3992 4485 e100_rts(info, 1); 3993 4486 e100_dtr(info, 1); 3994 - restore_flags(flags); 4487 + local_irq_restore(flags); 3995 4488 set_current_state(TASK_INTERRUPTIBLE); 3996 4489 if (tty_hung_up_p(filp) || 3997 4490 !(info->flags & ASYNC_INITIALIZED)) { ··· 4031 4528 return 0; 4032 4529 } 4033 4530 4531 + static void 4532 + deinit_port(struct e100_serial *info) 4533 + { 4534 + if (info->dma_out_enabled) { 4535 + cris_free_dma(info->dma_out_nbr, info->dma_out_irq_description); 4536 + free_irq(info->dma_out_irq_nbr, info); 4537 + } 4538 + if (info->dma_in_enabled) { 4539 + cris_free_dma(info->dma_in_nbr, info->dma_in_irq_description); 4540 + free_irq(info->dma_in_irq_nbr, info); 4541 + } 4542 + } 4543 + 4034 4544 /* 4035 4545 * This routine is called whenever a serial port is opened. 4036 4546 * It performs the serial-specific initialization for the tty structure. ··· 4054 4538 struct e100_serial *info; 4055 4539 int retval, line; 4056 4540 unsigned long page; 4541 + int allocated_resources = 0; 4057 4542 4058 4543 /* find which port we want to open */ 4059 - 4060 4544 line = tty->index; 4061 4545 4062 4546 if (line < 0 || line >= NR_PORTS) ··· 4096 4580 */ 4097 4581 if (tty_hung_up_p(filp) || 4098 4582 (info->flags & ASYNC_CLOSING)) { 4099 - if (info->flags & ASYNC_CLOSING) 4100 - interruptible_sleep_on(&info->close_wait); 4583 + wait_event_interruptible(info->close_wait, 4584 + !(info->flags & ASYNC_CLOSING)); 4101 4585 #ifdef SERIAL_DO_RESTART 4102 4586 return ((info->flags & ASYNC_HUP_NOTIFY) ? 4103 4587 -EAGAIN : -ERESTARTSYS); ··· 4107 4591 } 4108 4592 4109 4593 /* 4594 + * If DMA is enabled try to allocate the irq's. 4595 + */ 4596 + if (info->count == 1) { 4597 + allocated_resources = 1; 4598 + if (info->dma_in_enabled) { 4599 + if (request_irq(info->dma_in_irq_nbr, 4600 + rec_interrupt, 4601 + info->dma_in_irq_flags, 4602 + info->dma_in_irq_description, 4603 + info)) { 4604 + printk(KERN_WARNING "DMA irq '%s' busy; " 4605 + "falling back to non-DMA mode\n", 4606 + info->dma_in_irq_description); 4607 + /* Make sure we never try to use DMA in */ 4608 + /* for the port again. */ 4609 + info->dma_in_enabled = 0; 4610 + } else if (cris_request_dma(info->dma_in_nbr, 4611 + info->dma_in_irq_description, 4612 + DMA_VERBOSE_ON_ERROR, 4613 + info->dma_owner)) { 4614 + free_irq(info->dma_in_irq_nbr, info); 4615 + printk(KERN_WARNING "DMA '%s' busy; " 4616 + "falling back to non-DMA mode\n", 4617 + info->dma_in_irq_description); 4618 + /* Make sure we never try to use DMA in */ 4619 + /* for the port again. */ 4620 + info->dma_in_enabled = 0; 4621 + } 4622 + #ifdef SERIAL_DEBUG_OPEN 4623 + else 4624 + printk(KERN_DEBUG "DMA irq '%s' allocated\n", 4625 + info->dma_in_irq_description); 4626 + #endif 4627 + } 4628 + if (info->dma_out_enabled) { 4629 + if (request_irq(info->dma_out_irq_nbr, 4630 + tr_interrupt, 4631 + info->dma_out_irq_flags, 4632 + info->dma_out_irq_description, 4633 + info)) { 4634 + printk(KERN_WARNING "DMA irq '%s' busy; " 4635 + "falling back to non-DMA mode\n", 4636 + info->dma_out_irq_description); 4637 + /* Make sure we never try to use DMA out */ 4638 + /* for the port again. */ 4639 + info->dma_out_enabled = 0; 4640 + } else if (cris_request_dma(info->dma_out_nbr, 4641 + info->dma_out_irq_description, 4642 + DMA_VERBOSE_ON_ERROR, 4643 + info->dma_owner)) { 4644 + free_irq(info->dma_out_irq_nbr, info); 4645 + printk(KERN_WARNING "DMA '%s' busy; " 4646 + "falling back to non-DMA mode\n", 4647 + info->dma_out_irq_description); 4648 + /* Make sure we never try to use DMA out */ 4649 + /* for the port again. */ 4650 + info->dma_out_enabled = 0; 4651 + } 4652 + #ifdef SERIAL_DEBUG_OPEN 4653 + else 4654 + printk(KERN_DEBUG "DMA irq '%s' allocated\n", 4655 + info->dma_out_irq_description); 4656 + #endif 4657 + } 4658 + } 4659 + 4660 + /* 4110 4661 * Start up the serial port 4111 4662 */ 4112 4663 4113 4664 retval = startup(info); 4114 - if (retval) 4665 + if (retval) { 4666 + if (allocated_resources) 4667 + deinit_port(info); 4668 + 4669 + /* FIXME Decrease count info->count here too? */ 4115 4670 return retval; 4671 + } 4672 + 4116 4673 4117 4674 retval = block_til_ready(tty, filp, info); 4118 4675 if (retval) { ··· 4193 4604 printk("rs_open returning after block_til_ready with %d\n", 4194 4605 retval); 4195 4606 #endif 4607 + if (allocated_resources) 4608 + deinit_port(info); 4609 + 4196 4610 return retval; 4197 4611 } 4198 4612 ··· 4385 4793 .send_xchar = rs_send_xchar, 4386 4794 .wait_until_sent = rs_wait_until_sent, 4387 4795 .read_proc = rs_read_proc, 4796 + .tiocmget = rs_tiocmget, 4797 + .tiocmset = rs_tiocmset 4388 4798 }; 4389 4799 4390 4800 static int __init ··· 4404 4810 /* Setup the timed flush handler system */ 4405 4811 4406 4812 #if !defined(CONFIG_ETRAX_SERIAL_FAST_TIMER) 4407 - init_timer(&flush_timer); 4408 - flush_timer.function = timed_flush_handler; 4409 - mod_timer(&flush_timer, jiffies + CONFIG_ETRAX_SERIAL_RX_TIMEOUT_TICKS); 4813 + setup_timer(&flush_timer, timed_flush_handler, 0); 4814 + mod_timer(&flush_timer, jiffies + 5); 4815 + #endif 4816 + 4817 + #if defined(CONFIG_ETRAX_RS485) 4818 + #if defined(CONFIG_ETRAX_RS485_ON_PA) 4819 + if (cris_io_interface_allocate_pins(if_ser0, 'a', rs485_pa_bit, 4820 + rs485_pa_bit)) { 4821 + printk(KERN_CRIT "ETRAX100LX serial: Could not allocate " 4822 + "RS485 pin\n"); 4823 + return -EBUSY; 4824 + } 4825 + #endif 4826 + #if defined(CONFIG_ETRAX_RS485_ON_PORT_G) 4827 + if (cris_io_interface_allocate_pins(if_ser0, 'g', rs485_pa_bit, 4828 + rs485_port_g_bit)) { 4829 + printk(KERN_CRIT "ETRAX100LX serial: Could not allocate " 4830 + "RS485 pin\n"); 4831 + return -EBUSY; 4832 + } 4833 + #endif 4410 4834 #endif 4411 4835 4412 4836 /* Initialize the tty_driver structure */ ··· 4451 4839 /* do some initializing for the separate ports */ 4452 4840 4453 4841 for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) { 4842 + if (info->enabled) { 4843 + if (cris_request_io_interface(info->io_if, 4844 + info->io_if_description)) { 4845 + printk(KERN_CRIT "ETRAX100LX async serial: " 4846 + "Could not allocate IO pins for " 4847 + "%s, port %d\n", 4848 + info->io_if_description, i); 4849 + info->enabled = 0; 4850 + } 4851 + } 4454 4852 info->uses_dma_in = 0; 4455 4853 info->uses_dma_out = 0; 4456 4854 info->line = i; ··· 4494 4872 info->rs485.delay_rts_before_send = 0; 4495 4873 info->rs485.enabled = 0; 4496 4874 #endif 4497 - INIT_WORK(&info->work, do_softint, info); 4875 + INIT_WORK(&info->work, do_softint); 4498 4876 4499 4877 if (info->enabled) { 4500 4878 printk(KERN_INFO "%s%d at 0x%x is a builtin UART with DMA\n", ··· 4512 4890 #endif 4513 4891 4514 4892 #ifndef CONFIG_SVINTO_SIM 4893 + #ifndef CONFIG_ETRAX_KGDB 4515 4894 /* Not needed in simulator. May only complicate stuff. */ 4516 4895 /* hook the irq's for DMA channel 6 and 7, serial output and input, and some more... */ 4517 4896 4518 - if (request_irq(SERIAL_IRQ_NBR, ser_interrupt, IRQF_SHARED | IRQF_DISABLED, "serial ", NULL)) 4519 - panic("irq8"); 4897 + if (request_irq(SERIAL_IRQ_NBR, ser_interrupt, 4898 + IRQF_SHARED | IRQF_DISABLED, "serial ", driver)) 4899 + panic("%s: Failed to request irq8", __FUNCTION__); 4520 4900 4521 - #ifdef CONFIG_ETRAX_SERIAL_PORT0 4522 - #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA6_OUT 4523 - if (request_irq(SER0_DMA_TX_IRQ_NBR, tr_interrupt, IRQF_DISABLED, "serial 0 dma tr", NULL)) 4524 - panic("irq22"); 4525 - #endif 4526 - #ifdef CONFIG_ETRAX_SERIAL_PORT0_DMA7_IN 4527 - if (request_irq(SER0_DMA_RX_IRQ_NBR, rec_interrupt, IRQF_DISABLED, "serial 0 dma rec", NULL)) 4528 - panic("irq23"); 4529 - #endif 4530 - #endif 4531 - 4532 - #ifdef CONFIG_ETRAX_SERIAL_PORT1 4533 - #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA8_OUT 4534 - if (request_irq(SER1_DMA_TX_IRQ_NBR, tr_interrupt, IRQF_DISABLED, "serial 1 dma tr", NULL)) 4535 - panic("irq24"); 4536 - #endif 4537 - #ifdef CONFIG_ETRAX_SERIAL_PORT1_DMA9_IN 4538 - if (request_irq(SER1_DMA_RX_IRQ_NBR, rec_interrupt, IRQF_DISABLED, "serial 1 dma rec", NULL)) 4539 - panic("irq25"); 4540 - #endif 4541 - #endif 4542 - #ifdef CONFIG_ETRAX_SERIAL_PORT2 4543 - /* DMA Shared with par0 (and SCSI0 and ATA) */ 4544 - #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA2_OUT 4545 - if (request_irq(SER2_DMA_TX_IRQ_NBR, tr_interrupt, IRQF_SHARED | IRQF_DISABLED, "serial 2 dma tr", NULL)) 4546 - panic("irq18"); 4547 - #endif 4548 - #ifdef CONFIG_ETRAX_SERIAL_PORT2_DMA3_IN 4549 - if (request_irq(SER2_DMA_RX_IRQ_NBR, rec_interrupt, IRQF_SHARED | IRQF_DISABLED, "serial 2 dma rec", NULL)) 4550 - panic("irq19"); 4551 - #endif 4552 - #endif 4553 - #ifdef CONFIG_ETRAX_SERIAL_PORT3 4554 - /* DMA Shared with par1 (and SCSI1 and Extern DMA 0) */ 4555 - #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA4_OUT 4556 - if (request_irq(SER3_DMA_TX_IRQ_NBR, tr_interrupt, IRQF_SHARED | IRQF_DISABLED, "serial 3 dma tr", NULL)) 4557 - panic("irq20"); 4558 - #endif 4559 - #ifdef CONFIG_ETRAX_SERIAL_PORT3_DMA5_IN 4560 - if (request_irq(SER3_DMA_RX_IRQ_NBR, rec_interrupt, IRQF_SHARED | IRQF_DISABLED, "serial 3 dma rec", NULL)) 4561 - panic("irq21"); 4562 - #endif 4563 - #endif 4564 - 4565 - #ifdef CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST 4566 - if (request_irq(TIMER1_IRQ_NBR, timeout_interrupt, IRQF_SHARED | IRQF_DISABLED, 4567 - "fast serial dma timeout", NULL)) { 4568 - printk(KERN_CRIT "err: timer1 irq\n"); 4569 - } 4570 4901 #endif 4571 4902 #endif /* CONFIG_SVINTO_SIM */ 4572 - debug_write_function = rs_debug_write_function; 4903 + 4573 4904 return 0; 4574 4905 } 4575 4906
+146
drivers/serial/crisv10.h
··· 1 + /* 2 + * serial.h: Arch-dep definitions for the Etrax100 serial driver. 3 + * 4 + * Copyright (C) 1998-2007 Axis Communications AB 5 + */ 6 + 7 + #ifndef _ETRAX_SERIAL_H 8 + #define _ETRAX_SERIAL_H 9 + 10 + #include <linux/circ_buf.h> 11 + #include <asm/termios.h> 12 + #include <asm/dma.h> 13 + #include <asm/arch/io_interface_mux.h> 14 + 15 + /* Software state per channel */ 16 + 17 + #ifdef __KERNEL__ 18 + /* 19 + * This is our internal structure for each serial port's state. 20 + * 21 + * Many fields are paralleled by the structure used by the serial_struct 22 + * structure. 23 + * 24 + * For definitions of the flags field, see tty.h 25 + */ 26 + 27 + #define SERIAL_RECV_DESCRIPTORS 8 28 + 29 + struct etrax_recv_buffer { 30 + struct etrax_recv_buffer *next; 31 + unsigned short length; 32 + unsigned char error; 33 + unsigned char pad; 34 + 35 + unsigned char buffer[0]; 36 + }; 37 + 38 + struct e100_serial { 39 + int baud; 40 + volatile u8 *port; /* R_SERIALx_CTRL */ 41 + u32 irq; /* bitnr in R_IRQ_MASK2 for dmaX_descr */ 42 + 43 + /* Output registers */ 44 + volatile u8 *oclrintradr; /* adr to R_DMA_CHx_CLR_INTR */ 45 + volatile u32 *ofirstadr; /* adr to R_DMA_CHx_FIRST */ 46 + volatile u8 *ocmdadr; /* adr to R_DMA_CHx_CMD */ 47 + const volatile u8 *ostatusadr; /* adr to R_DMA_CHx_STATUS */ 48 + 49 + /* Input registers */ 50 + volatile u8 *iclrintradr; /* adr to R_DMA_CHx_CLR_INTR */ 51 + volatile u32 *ifirstadr; /* adr to R_DMA_CHx_FIRST */ 52 + volatile u8 *icmdadr; /* adr to R_DMA_CHx_CMD */ 53 + volatile u32 *idescradr; /* adr to R_DMA_CHx_DESCR */ 54 + 55 + int flags; /* defined in tty.h */ 56 + 57 + u8 rx_ctrl; /* shadow for R_SERIALx_REC_CTRL */ 58 + u8 tx_ctrl; /* shadow for R_SERIALx_TR_CTRL */ 59 + u8 iseteop; /* bit number for R_SET_EOP for the input dma */ 60 + int enabled; /* Set to 1 if the port is enabled in HW config */ 61 + 62 + u8 dma_out_enabled; /* Set to 1 if DMA should be used */ 63 + u8 dma_in_enabled; /* Set to 1 if DMA should be used */ 64 + 65 + /* end of fields defined in rs_table[] in .c-file */ 66 + int dma_owner; 67 + unsigned int dma_in_nbr; 68 + unsigned int dma_out_nbr; 69 + unsigned int dma_in_irq_nbr; 70 + unsigned int dma_out_irq_nbr; 71 + unsigned long dma_in_irq_flags; 72 + unsigned long dma_out_irq_flags; 73 + char *dma_in_irq_description; 74 + char *dma_out_irq_description; 75 + 76 + enum cris_io_interface io_if; 77 + char *io_if_description; 78 + 79 + u8 uses_dma_in; /* Set to 1 if DMA is used */ 80 + u8 uses_dma_out; /* Set to 1 if DMA is used */ 81 + u8 forced_eop; /* a fifo eop has been forced */ 82 + int baud_base; /* For special baudrates */ 83 + int custom_divisor; /* For special baudrates */ 84 + struct etrax_dma_descr tr_descr; 85 + struct etrax_dma_descr rec_descr[SERIAL_RECV_DESCRIPTORS]; 86 + int cur_rec_descr; 87 + 88 + volatile int tr_running; /* 1 if output is running */ 89 + 90 + struct tty_struct *tty; 91 + int read_status_mask; 92 + int ignore_status_mask; 93 + int x_char; /* xon/xoff character */ 94 + int close_delay; 95 + unsigned short closing_wait; 96 + unsigned short closing_wait2; 97 + unsigned long event; 98 + unsigned long last_active; 99 + int line; 100 + int type; /* PORT_ETRAX */ 101 + int count; /* # of fd on device */ 102 + int blocked_open; /* # of blocked opens */ 103 + struct circ_buf xmit; 104 + struct etrax_recv_buffer *first_recv_buffer; 105 + struct etrax_recv_buffer *last_recv_buffer; 106 + unsigned int recv_cnt; 107 + unsigned int max_recv_cnt; 108 + 109 + struct work_struct work; 110 + struct async_icount icount; /* error-statistics etc.*/ 111 + struct ktermios normal_termios; 112 + struct ktermios callout_termios; 113 + wait_queue_head_t open_wait; 114 + wait_queue_head_t close_wait; 115 + 116 + unsigned long char_time_usec; /* The time for 1 char, in usecs */ 117 + unsigned long flush_time_usec; /* How often we should flush */ 118 + unsigned long last_tx_active_usec; /* Last tx usec in the jiffies */ 119 + unsigned long last_tx_active; /* Last tx time in jiffies */ 120 + unsigned long last_rx_active_usec; /* Last rx usec in the jiffies */ 121 + unsigned long last_rx_active; /* Last rx time in jiffies */ 122 + 123 + int break_detected_cnt; 124 + int errorcode; 125 + 126 + #ifdef CONFIG_ETRAX_RS485 127 + struct rs485_control rs485; /* RS-485 support */ 128 + #endif 129 + }; 130 + 131 + /* this PORT is not in the standard serial.h. it's not actually used for 132 + * anything since we only have one type of async serial-port anyway in this 133 + * system. 134 + */ 135 + 136 + #define PORT_ETRAX 1 137 + 138 + /* 139 + * Events are used to schedule things to happen at timer-interrupt 140 + * time, instead of at rs interrupt time. 141 + */ 142 + #define RS_EVENT_WRITE_WAKEUP 0 143 + 144 + #endif /* __KERNEL__ */ 145 + 146 + #endif /* !_ETRAX_SERIAL_H */