aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2008-04-30 03:54:16 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-30 11:29:47 -0400
commitfb100b6ea7bf8a95e52b90cc0dc0ea5744a0a40a (patch)
tree651b67c8fbd222bd1841716b0184a575ef5a4690 /drivers
parent191260a01257793ad76cc35b7f9e1508d27bdd4b (diff)
esp: clean up to modern coding style
Signed-off-by: Alan Cox <alan@redhat.com> Cc: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/esp.c591
1 files changed, 283 insertions, 308 deletions
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index 996d3230c929..9525eacc4758 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -8,7 +8,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.
@@ -61,11 +61,11 @@
61#include <linux/bitops.h> 61#include <linux/bitops.h>
62 62
63#include <asm/system.h> 63#include <asm/system.h>
64#include <asm/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 <asm/uaccess.h> 68#include <linux/uaccess.h>
69 69
70#include <linux/hayesesp.h> 70#include <linux/hayesesp.h>
71 71
@@ -127,8 +127,10 @@ static struct tty_driver *esp_driver;
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("(%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), serial_driver.refcount,info->count,tty->count,s) 131 tty->name, info->flags, \
132 serial_driver.refcount, \
133 info->count, tty->count, s)
132#else 134#else
133#define DBG_CNT(s) 135#define DBG_CNT(s)
134#endif 136#endif
@@ -189,7 +191,7 @@ static inline void serial_out(struct esp_struct *info, int offset,
189 */ 191 */
190static void rs_stop(struct tty_struct *tty) 192static void rs_stop(struct tty_struct *tty)
191{ 193{
192 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 194 struct esp_struct *info = tty->driver_data;
193 unsigned long flags; 195 unsigned long flags;
194 196
195 if (serial_paranoia_check(info, tty->name, "rs_stop")) 197 if (serial_paranoia_check(info, tty->name, "rs_stop"))
@@ -206,12 +208,12 @@ static void rs_stop(struct tty_struct *tty)
206 208
207static void rs_start(struct tty_struct *tty) 209static void rs_start(struct tty_struct *tty)
208{ 210{
209 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 211 struct esp_struct *info = tty->driver_data;
210 unsigned long flags; 212 unsigned long flags;
211 213
212 if (serial_paranoia_check(info, tty->name, "rs_start")) 214 if (serial_paranoia_check(info, tty->name, "rs_start"))
213 return; 215 return;
214 216
215 spin_lock_irqsave(&info->lock, flags); 217 spin_lock_irqsave(&info->lock, flags);
216 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)) {
217 info->IER |= UART_IER_THRI; 219 info->IER |= UART_IER_THRI;
@@ -233,7 +235,7 @@ static void rs_start(struct tty_struct *tty)
233 * 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
234 * 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
235 * idea to do: 237 * idea to do:
236 * 238 *
237 * 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
238 * 240 *
239 * and look at the resulting assemble code in serial.s. 241 * and look at the resulting assemble code in serial.s.
@@ -290,7 +292,7 @@ static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
290 } 292 }
291 293
292 status_mask = (info->read_status_mask >> 2) & 0x07; 294 status_mask = (info->read_status_mask >> 2) & 0x07;
293 295
294 for (i = 0; i < num_bytes - 1; i += 2) { 296 for (i = 0; i < num_bytes - 1; i += 2) {
295 *((unsigned short *)(pio_buf->data + i)) = 297 *((unsigned short *)(pio_buf->data + i)) =
296 inw(info->port + UART_ESI_RX); 298 inw(info->port + UART_ESI_RX);
@@ -325,8 +327,7 @@ static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
325 flag = TTY_BREAK; 327 flag = TTY_BREAK;
326 if (info->flags & ASYNC_SAK) 328 if (info->flags & ASYNC_SAK)
327 do_SAK(tty); 329 do_SAK(tty);
328 } 330 } else if (err_buf->data[i] & 0x02)
329 else if (err_buf->data[i] & 0x02)
330 flag = TTY_FRAME; 331 flag = TTY_FRAME;
331 else if (err_buf->data[i] & 0x01) 332 else if (err_buf->data[i] & 0x01)
332 flag = TTY_PARITY; 333 flag = TTY_PARITY;
@@ -341,23 +342,29 @@ static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
341 release_pio_buffer(err_buf); 342 release_pio_buffer(err_buf);
342} 343}
343 344
344static inline void receive_chars_dma(struct esp_struct *info, int num_bytes) 345static void program_isa_dma(int dma, int dir, unsigned long addr, int len)
345{ 346{
346 unsigned long flags; 347 unsigned long flags;
348
349 flags = claim_dma_lock();
350 disable_dma(dma);
351 clear_dma_ff(dma);
352 set_dma_mode(dma, dir);
353 set_dma_addr(dma, addr);
354 set_dma_count(dma, len);
355 enable_dma(dma);
356 release_dma_lock(flags);
357}
358
359static void receive_chars_dma(struct esp_struct *info, int num_bytes)
360{
347 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT; 361 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
348 dma_bytes = num_bytes; 362 dma_bytes = num_bytes;
349 info->stat_flags |= ESP_STAT_DMA_RX; 363 info->stat_flags |= ESP_STAT_DMA_RX;
350 364
351 flags=claim_dma_lock(); 365 program_isa_dma(dma, DMA_MODE_READ, isa_virt_to_bus(dma_buffer),
352 disable_dma(dma); 366 dma_bytes);
353 clear_dma_ff(dma); 367 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX);
354 set_dma_mode(dma, DMA_MODE_READ);
355 set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
356 set_dma_count(dma, dma_bytes);
357 enable_dma(dma);
358 release_dma_lock(flags);
359
360 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX);
361} 368}
362 369
363static inline void receive_chars_dma_done(struct esp_struct *info, 370static inline void receive_chars_dma_done(struct esp_struct *info,
@@ -366,22 +373,22 @@ static inline void receive_chars_dma_done(struct esp_struct *info,
366 struct tty_struct *tty = info->tty; 373 struct tty_struct *tty = info->tty;
367 int num_bytes; 374 int num_bytes;
368 unsigned long flags; 375 unsigned long flags;
369 376
370 flags=claim_dma_lock(); 377 flags = claim_dma_lock();
371 disable_dma(dma); 378 disable_dma(dma);
372 clear_dma_ff(dma); 379 clear_dma_ff(dma);
373 380
374 info->stat_flags &= ~ESP_STAT_DMA_RX; 381 info->stat_flags &= ~ESP_STAT_DMA_RX;
375 num_bytes = dma_bytes - get_dma_residue(dma); 382 num_bytes = dma_bytes - get_dma_residue(dma);
376 release_dma_lock(flags); 383 release_dma_lock(flags);
377 384
378 info->icount.rx += num_bytes; 385 info->icount.rx += num_bytes;
379 386
380 if (num_bytes > 0) { 387 if (num_bytes > 0) {
381 tty_insert_flip_string(tty, dma_buffer, num_bytes - 1); 388 tty_insert_flip_string(tty, dma_buffer, num_bytes - 1);
382 389
383 status &= (0x1c & info->read_status_mask); 390 status &= (0x1c & info->read_status_mask);
384 391
385 /* Is the status significant or do we throw the last byte ? */ 392 /* Is the status significant or do we throw the last byte ? */
386 if (!(status & info->ignore_status_mask)) { 393 if (!(status & info->ignore_status_mask)) {
387 int statflag = 0; 394 int statflag = 0;
@@ -393,13 +400,13 @@ static inline void receive_chars_dma_done(struct esp_struct *info,
393 do_SAK(tty); 400 do_SAK(tty);
394 } else if (status & 0x08) { 401 } else if (status & 0x08) {
395 statflag = TTY_FRAME; 402 statflag = TTY_FRAME;
396 (info->icount.frame)++; 403 info->icount.frame++;
397 } 404 } else if (status & 0x04) {
398 else if (status & 0x04) {
399 statflag = TTY_PARITY; 405 statflag = TTY_PARITY;
400 (info->icount.parity)++; 406 info->icount.parity++;
401 } 407 }
402 tty_insert_flip_char(tty, dma_buffer[num_bytes - 1], statflag); 408 tty_insert_flip_char(tty, dma_buffer[num_bytes - 1],
409 statflag);
403 } 410 }
404 tty_schedule_flip(tty); 411 tty_schedule_flip(tty);
405 } 412 }
@@ -484,8 +491,6 @@ static inline void transmit_chars_pio(struct esp_struct *info,
484/* Caller must hold info->lock */ 491/* Caller must hold info->lock */
485static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes) 492static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes)
486{ 493{
487 unsigned long flags;
488
489 dma_bytes = num_bytes; 494 dma_bytes = num_bytes;
490 495
491 if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) { 496 if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) {
@@ -517,26 +522,18 @@ static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes)
517 } 522 }
518 523
519 info->stat_flags |= ESP_STAT_DMA_TX; 524 info->stat_flags |= ESP_STAT_DMA_TX;
520 525
521 flags=claim_dma_lock(); 526 program_isa_dma(dma, DMA_MODE_WRITE, isa_virt_to_bus(dma_buffer),
522 disable_dma(dma); 527 dma_bytes);
523 clear_dma_ff(dma); 528 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
524 set_dma_mode(dma, DMA_MODE_WRITE);
525 set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
526 set_dma_count(dma, dma_bytes);
527 enable_dma(dma);
528 release_dma_lock(flags);
529
530 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
531} 529}
532 530
533static inline void transmit_chars_dma_done(struct esp_struct *info) 531static inline void transmit_chars_dma_done(struct esp_struct *info)
534{ 532{
535 int num_bytes; 533 int num_bytes;
536 unsigned long flags; 534 unsigned long flags;
537
538 535
539 flags=claim_dma_lock(); 536 flags = claim_dma_lock();
540 disable_dma(dma); 537 disable_dma(dma);
541 clear_dma_ff(dma); 538 clear_dma_ff(dma);
542 539
@@ -547,27 +544,21 @@ static inline void transmit_chars_dma_done(struct esp_struct *info)
547 if (dma_bytes != num_bytes) { 544 if (dma_bytes != num_bytes) {
548 dma_bytes -= num_bytes; 545 dma_bytes -= num_bytes;
549 memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes); 546 memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes);
550 547
551 flags=claim_dma_lock(); 548 program_isa_dma(dma, DMA_MODE_WRITE,
552 disable_dma(dma); 549 isa_virt_to_bus(dma_buffer), dma_bytes);
553 clear_dma_ff(dma); 550
554 set_dma_mode(dma, DMA_MODE_WRITE); 551 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
555 set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
556 set_dma_count(dma, dma_bytes);
557 enable_dma(dma);
558 release_dma_lock(flags);
559
560 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
561 } else { 552 } else {
562 dma_bytes = 0; 553 dma_bytes = 0;
563 info->stat_flags &= ~ESP_STAT_DMA_TX; 554 info->stat_flags &= ~ESP_STAT_DMA_TX;
564 } 555 }
565} 556}
566 557
567static inline void check_modem_status(struct esp_struct *info) 558static void check_modem_status(struct esp_struct *info)
568{ 559{
569 int status; 560 int status;
570 561
571 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); 562 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
572 status = serial_in(info, UART_ESI_STAT2); 563 status = serial_in(info, UART_ESI_STAT2);
573 564
@@ -588,7 +579,7 @@ static inline void check_modem_status(struct esp_struct *info)
588#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR)) 579#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
589 printk("ttys%d CD now %s...", info->line, 580 printk("ttys%d CD now %s...", info->line,
590 (status & UART_MSR_DCD) ? "on" : "off"); 581 (status & UART_MSR_DCD) ? "on" : "off");
591#endif 582#endif
592 if (status & UART_MSR_DCD) 583 if (status & UART_MSR_DCD)
593 wake_up_interruptible(&info->open_wait); 584 wake_up_interruptible(&info->open_wait);
594 else { 585 else {
@@ -605,7 +596,7 @@ static inline void check_modem_status(struct esp_struct *info)
605 */ 596 */
606static irqreturn_t rs_interrupt_single(int irq, void *dev_id) 597static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
607{ 598{
608 struct esp_struct * info; 599 struct esp_struct *info;
609 unsigned err_status; 600 unsigned err_status;
610 unsigned int scratch; 601 unsigned int scratch;
611 602
@@ -617,7 +608,7 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
617 scratch = serial_in(info, UART_ESI_SID); 608 scratch = serial_in(info, UART_ESI_SID);
618 609
619 spin_lock(&info->lock); 610 spin_lock(&info->lock);
620 611
621 if (!info->tty) { 612 if (!info->tty) {
622 spin_unlock(&info->lock); 613 spin_unlock(&info->lock);
623 return IRQ_NONE; 614 return IRQ_NONE;
@@ -637,7 +628,7 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
637 if (err_status & 0x80) /* Start break */ 628 if (err_status & 0x80) /* Start break */
638 wake_up_interruptible(&info->break_wait); 629 wake_up_interruptible(&info->break_wait);
639 } 630 }
640 631
641 if ((scratch & 0x88) || /* DMA completed or timed out */ 632 if ((scratch & 0x88) || /* DMA completed or timed out */
642 (err_status & 0x1c) /* receive error */) { 633 (err_status & 0x1c) /* receive error */) {
643 if (info->stat_flags & ESP_STAT_DMA_RX) 634 if (info->stat_flags & ESP_STAT_DMA_RX)
@@ -667,7 +658,7 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
667 receive_chars_dma(info, num_bytes); 658 receive_chars_dma(info, num_bytes);
668 } 659 }
669 } 660 }
670 661
671 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)) &&
672 (scratch & 0x02) && (info->IER & UART_IER_THRI)) { 663 (scratch & 0x02) && (info->IER & UART_IER_THRI)) {
673 if ((info->xmit_cnt <= 0) || info->tty->stopped) { 664 if ((info->xmit_cnt <= 0) || info->tty->stopped) {
@@ -722,11 +713,11 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
722 * --------------------------------------------------------------- 713 * ---------------------------------------------------------------
723 */ 714 */
724 715
725static inline void esp_basic_init(struct esp_struct * info) 716static void esp_basic_init(struct esp_struct *info)
726{ 717{
727 /* put ESPC in enhanced mode */ 718 /* put ESPC in enhanced mode */
728 serial_out(info, UART_ESI_CMD1, ESI_SET_MODE); 719 serial_out(info, UART_ESI_CMD1, ESI_SET_MODE);
729 720
730 if (info->stat_flags & ESP_STAT_NEVER_DMA) 721 if (info->stat_flags & ESP_STAT_NEVER_DMA)
731 serial_out(info, UART_ESI_CMD2, 0x01); 722 serial_out(info, UART_ESI_CMD2, 0x01);
732 else 723 else
@@ -783,13 +774,13 @@ static inline void esp_basic_init(struct esp_struct * info)
783 serial_out(info, UART_ESI_CMD2, 0xff); 774 serial_out(info, UART_ESI_CMD2, 0xff);
784} 775}
785 776
786static int startup(struct esp_struct * info) 777static int startup(struct esp_struct *info)
787{ 778{
788 unsigned long flags; 779 unsigned long flags;
789 int retval=0; 780 int retval = 0;
790 unsigned int num_chars; 781 unsigned int num_chars;
791 782
792 spin_lock_irqsave(&info->lock, flags); 783 spin_lock_irqsave(&info->lock, flags);
793 784
794 if (info->flags & ASYNC_INITIALIZED) 785 if (info->flags & ASYNC_INITIALIZED)
795 goto out; 786 goto out;
@@ -802,7 +793,8 @@ static int startup(struct esp_struct * info)
802 } 793 }
803 794
804#ifdef SERIAL_DEBUG_OPEN 795#ifdef SERIAL_DEBUG_OPEN
805 printk("starting up ttys%d (irq %d)...", info->line, info->irq); 796 printk(KERN_DEBUG "starting up ttys%d (irq %d)...",
797 info->line, info->irq);
806#endif 798#endif
807 799
808 /* Flush the RX buffer. Using the ESI flush command may cause */ 800 /* Flush the RX buffer. Using the ESI flush command may cause */
@@ -863,7 +855,7 @@ static int startup(struct esp_struct * info)
863 dma_buffer = NULL; 855 dma_buffer = NULL;
864 info->stat_flags |= ESP_STAT_USE_PIO; 856 info->stat_flags |= ESP_STAT_USE_PIO;
865 } 857 }
866 858
867 } 859 }
868 860
869 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; 861 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
@@ -872,7 +864,7 @@ static int startup(struct esp_struct * info)
872 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 864 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
873 serial_out(info, UART_ESI_CMD2, UART_MCR); 865 serial_out(info, UART_ESI_CMD2, UART_MCR);
874 serial_out(info, UART_ESI_CMD2, info->MCR); 866 serial_out(info, UART_ESI_CMD2, info->MCR);
875 867
876 /* 868 /*
877 * Finally, enable interrupts 869 * Finally, enable interrupts
878 */ 870 */
@@ -881,7 +873,7 @@ static int startup(struct esp_struct * info)
881 UART_IER_DMA_TC; 873 UART_IER_DMA_TC;
882 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 874 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
883 serial_out(info, UART_ESI_CMD2, info->IER); 875 serial_out(info, UART_ESI_CMD2, info->IER);
884 876
885 if (info->tty) 877 if (info->tty)
886 clear_bit(TTY_IO_ERROR, &info->tty->flags); 878 clear_bit(TTY_IO_ERROR, &info->tty->flags);
887 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 879 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
@@ -900,7 +892,7 @@ static int startup(struct esp_struct * info)
900 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 892 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
901 info->tty->alt_speed = 460800; 893 info->tty->alt_speed = 460800;
902 } 894 }
903 895
904 /* 896 /*
905 * set the speed of the serial port 897 * set the speed of the serial port
906 */ 898 */
@@ -918,7 +910,7 @@ out_unlocked:
918 * This routine will shutdown a serial port; interrupts are disabled, and 910 * This routine will shutdown a serial port; interrupts are disabled, and
919 * 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.
920 */ 912 */
921static void shutdown(struct esp_struct * info) 913static void shutdown(struct esp_struct *info)
922{ 914{
923 unsigned long flags, f; 915 unsigned long flags, f;
924 916
@@ -929,7 +921,7 @@ static void shutdown(struct esp_struct * info)
929 printk("Shutting down serial port %d (irq %d)....", info->line, 921 printk("Shutting down serial port %d (irq %d)....", info->line,
930 info->irq); 922 info->irq);
931#endif 923#endif
932 924
933 spin_lock_irqsave(&info->lock, flags); 925 spin_lock_irqsave(&info->lock, flags);
934 /* 926 /*
935 * 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
@@ -941,14 +933,14 @@ static void shutdown(struct esp_struct * info)
941 /* stop a DMA transfer on the port being closed */ 933 /* stop a DMA transfer on the port being closed */
942 /* DMA lock is higher priority always */ 934 /* DMA lock is higher priority always */
943 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)) {
944 f=claim_dma_lock(); 936 f = claim_dma_lock();
945 disable_dma(dma); 937 disable_dma(dma);
946 clear_dma_ff(dma); 938 clear_dma_ff(dma);
947 release_dma_lock(f); 939 release_dma_lock(f);
948 940
949 dma_bytes = 0; 941 dma_bytes = 0;
950 } 942 }
951 943
952 /* 944 /*
953 * Free the IRQ 945 * Free the IRQ
954 */ 946 */
@@ -970,7 +962,7 @@ static void shutdown(struct esp_struct * info)
970 free_pages((unsigned long)dma_buffer, 962 free_pages((unsigned long)dma_buffer,
971 get_order(DMA_BUFFER_SZ)); 963 get_order(DMA_BUFFER_SZ));
972 dma_buffer = NULL; 964 dma_buffer = NULL;
973 } 965 }
974 } 966 }
975 967
976 if (info->xmit_buf) { 968 if (info->xmit_buf) {
@@ -992,7 +984,7 @@ static void shutdown(struct esp_struct * info)
992 984
993 if (info->tty) 985 if (info->tty)
994 set_bit(TTY_IO_ERROR, &info->tty->flags); 986 set_bit(TTY_IO_ERROR, &info->tty->flags);
995 987
996 info->flags &= ~ASYNC_INITIALIZED; 988 info->flags &= ~ASYNC_INITIALIZED;
997 spin_unlock_irqrestore(&info->lock, flags); 989 spin_unlock_irqrestore(&info->lock, flags);
998} 990}
@@ -1005,7 +997,7 @@ static void change_speed(struct esp_struct *info)
1005{ 997{
1006 unsigned short port; 998 unsigned short port;
1007 int quot = 0; 999 int quot = 0;
1008 unsigned cflag,cval; 1000 unsigned cflag, cval;
1009 int baud, bits; 1001 int baud, bits;
1010 unsigned char flow1 = 0, flow2 = 0; 1002 unsigned char flow1 = 0, flow2 = 0;
1011 unsigned long flags; 1003 unsigned long flags;
@@ -1014,14 +1006,14 @@ static void change_speed(struct esp_struct *info)
1014 return; 1006 return;
1015 cflag = info->tty->termios->c_cflag; 1007 cflag = info->tty->termios->c_cflag;
1016 port = info->port; 1008 port = info->port;
1017 1009
1018 /* byte size and parity */ 1010 /* byte size and parity */
1019 switch (cflag & CSIZE) { 1011 switch (cflag & CSIZE) {
1020 case CS5: cval = 0x00; bits = 7; break; 1012 case CS5: cval = 0x00; bits = 7; break;
1021 case CS6: cval = 0x01; bits = 8; break; 1013 case CS6: cval = 0x01; bits = 8; break;
1022 case CS7: cval = 0x02; bits = 9; break; 1014 case CS7: cval = 0x02; bits = 9; break;
1023 case CS8: cval = 0x03; bits = 10; break; 1015 case CS8: cval = 0x03; bits = 10; break;
1024 default: cval = 0x00; bits = 7; break; 1016 default: cval = 0x00; bits = 7; break;
1025 } 1017 }
1026 if (cflag & CSTOPB) { 1018 if (cflag & CSTOPB) {
1027 cval |= 0x04; 1019 cval |= 0x04;
@@ -1037,14 +1029,12 @@ static void change_speed(struct esp_struct *info)
1037 if (cflag & CMSPAR) 1029 if (cflag & CMSPAR)
1038 cval |= UART_LCR_SPAR; 1030 cval |= UART_LCR_SPAR;
1039#endif 1031#endif
1040
1041 baud = tty_get_baud_rate(info->tty); 1032 baud = tty_get_baud_rate(info->tty);
1042 if (baud == 38400 && 1033 if (baud == 38400 &&
1043 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) 1034 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1044 quot = info->custom_divisor; 1035 quot = info->custom_divisor;
1045 else { 1036 else {
1046 if (baud == 134) 1037 if (baud == 134) /* Special case since 134 is really 134.5 */
1047 /* Special case since 134 is really 134.5 */
1048 quot = (2*BASE_BAUD / 269); 1038 quot = (2*BASE_BAUD / 269);
1049 else if (baud) 1039 else if (baud)
1050 quot = BASE_BAUD / baud; 1040 quot = BASE_BAUD / baud;
@@ -1052,7 +1042,12 @@ static void change_speed(struct esp_struct *info)
1052 /* If the quotient is ever zero, default to 9600 bps */ 1042 /* If the quotient is ever zero, default to 9600 bps */
1053 if (!quot) 1043 if (!quot)
1054 quot = BASE_BAUD / 9600; 1044 quot = BASE_BAUD / 9600;
1055 1045
1046 if (baud) {
1047 /* Actual rate */
1048 baud = BASE_BAUD/quot;
1049 tty_encode_baud_rate(info->tty, baud, baud);
1050 }
1056 info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50); 1051 info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50);
1057 1052
1058 /* CTS flow control flag and modem status interrupts */ 1053 /* CTS flow control flag and modem status interrupts */
@@ -1066,10 +1061,8 @@ static void change_speed(struct esp_struct *info)
1066 info->flags &= ~ASYNC_CTS_FLOW; 1061 info->flags &= ~ASYNC_CTS_FLOW;
1067 if (cflag & CLOCAL) 1062 if (cflag & CLOCAL)
1068 info->flags &= ~ASYNC_CHECK_CD; 1063 info->flags &= ~ASYNC_CHECK_CD;
1069 else { 1064 else
1070 info->flags |= ASYNC_CHECK_CD; 1065 info->flags |= ASYNC_CHECK_CD;
1071 /* info->IER |= UART_IER_MSI; */
1072 }
1073 1066
1074 /* 1067 /*
1075 * Set up parity check flag 1068 * Set up parity check flag
@@ -1079,7 +1072,7 @@ static void change_speed(struct esp_struct *info)
1079 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 1072 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1080 if (I_BRKINT(info->tty) || I_PARMRK(info->tty)) 1073 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
1081 info->read_status_mask |= UART_LSR_BI; 1074 info->read_status_mask |= UART_LSR_BI;
1082 1075
1083 info->ignore_status_mask = 0; 1076 info->ignore_status_mask = 0;
1084#if 0 1077#if 0
1085 /* This should be safe, but for some broken bits of hardware... */ 1078 /* This should be safe, but for some broken bits of hardware... */
@@ -1092,7 +1085,7 @@ static void change_speed(struct esp_struct *info)
1092 info->ignore_status_mask |= UART_LSR_BI; 1085 info->ignore_status_mask |= UART_LSR_BI;
1093 info->read_status_mask |= UART_LSR_BI; 1086 info->read_status_mask |= UART_LSR_BI;
1094 /* 1087 /*
1095 * If we're ignore parity and break indicators, ignore 1088 * If we're ignore parity and break indicators, ignore
1096 * overruns too. (For real raw support). 1089 * overruns too. (For real raw support).
1097 */ 1090 */
1098 if (I_IGNPAR(info->tty)) { 1091 if (I_IGNPAR(info->tty)) {
@@ -1130,19 +1123,19 @@ static void change_speed(struct esp_struct *info)
1130 serial_out(info, UART_ESI_CMD2, 0x10); 1123 serial_out(info, UART_ESI_CMD2, 0x10);
1131 serial_out(info, UART_ESI_CMD2, 0x21); 1124 serial_out(info, UART_ESI_CMD2, 0x21);
1132 switch (cflag & CSIZE) { 1125 switch (cflag & CSIZE) {
1133 case CS5: 1126 case CS5:
1134 serial_out(info, UART_ESI_CMD2, 0x1f); 1127 serial_out(info, UART_ESI_CMD2, 0x1f);
1135 break; 1128 break;
1136 case CS6: 1129 case CS6:
1137 serial_out(info, UART_ESI_CMD2, 0x3f); 1130 serial_out(info, UART_ESI_CMD2, 0x3f);
1138 break; 1131 break;
1139 case CS7: 1132 case CS7:
1140 case CS8: 1133 case CS8:
1141 serial_out(info, UART_ESI_CMD2, 0x7f); 1134 serial_out(info, UART_ESI_CMD2, 0x7f);
1142 break; 1135 break;
1143 default: 1136 default:
1144 serial_out(info, UART_ESI_CMD2, 0xff); 1137 serial_out(info, UART_ESI_CMD2, 0xff);
1145 break; 1138 break;
1146 } 1139 }
1147 } 1140 }
1148 1141
@@ -1158,7 +1151,7 @@ static void change_speed(struct esp_struct *info)
1158 1151
1159static int rs_put_char(struct tty_struct *tty, unsigned char ch) 1152static int rs_put_char(struct tty_struct *tty, unsigned char ch)
1160{ 1153{
1161 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1154 struct esp_struct *info = tty->driver_data;
1162 unsigned long flags; 1155 unsigned long flags;
1163 int ret = 0; 1156 int ret = 0;
1164 1157
@@ -1181,9 +1174,9 @@ static int rs_put_char(struct tty_struct *tty, unsigned char ch)
1181 1174
1182static void rs_flush_chars(struct tty_struct *tty) 1175static void rs_flush_chars(struct tty_struct *tty)
1183{ 1176{
1184 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1177 struct esp_struct *info = tty->driver_data;
1185 unsigned long flags; 1178 unsigned long flags;
1186 1179
1187 if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) 1180 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
1188 return; 1181 return;
1189 1182
@@ -1201,11 +1194,11 @@ out:
1201 spin_unlock_irqrestore(&info->lock, flags); 1194 spin_unlock_irqrestore(&info->lock, flags);
1202} 1195}
1203 1196
1204static int rs_write(struct tty_struct * tty, 1197static int rs_write(struct tty_struct *tty,
1205 const unsigned char *buf, int count) 1198 const unsigned char *buf, int count)
1206{ 1199{
1207 int c, t, ret = 0; 1200 int c, t, ret = 0;
1208 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1201 struct esp_struct *info = tty->driver_data;
1209 unsigned long flags; 1202 unsigned long flags;
1210 1203
1211 if (serial_paranoia_check(info, tty->name, "rs_write")) 1204 if (serial_paranoia_check(info, tty->name, "rs_write"))
@@ -1213,19 +1206,19 @@ static int rs_write(struct tty_struct * tty,
1213 1206
1214 if (!info->xmit_buf) 1207 if (!info->xmit_buf)
1215 return 0; 1208 return 0;
1216 1209
1217 while (1) { 1210 while (1) {
1218 /* Thanks to R. Wolff for suggesting how to do this with */ 1211 /* Thanks to R. Wolff for suggesting how to do this with */
1219 /* interrupts enabled */ 1212 /* interrupts enabled */
1220 1213
1221 c = count; 1214 c = count;
1222 t = ESP_XMIT_SIZE - info->xmit_cnt - 1; 1215 t = ESP_XMIT_SIZE - info->xmit_cnt - 1;
1223 1216
1224 if (t < c) 1217 if (t < c)
1225 c = t; 1218 c = t;
1226 1219
1227 t = ESP_XMIT_SIZE - info->xmit_head; 1220 t = ESP_XMIT_SIZE - info->xmit_head;
1228 1221
1229 if (t < c) 1222 if (t < c)
1230 c = t; 1223 c = t;
1231 1224
@@ -1255,10 +1248,10 @@ static int rs_write(struct tty_struct * tty,
1255 1248
1256static int rs_write_room(struct tty_struct *tty) 1249static int rs_write_room(struct tty_struct *tty)
1257{ 1250{
1258 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1251 struct esp_struct *info = tty->driver_data;
1259 int ret; 1252 int ret;
1260 unsigned long flags; 1253 unsigned long flags;
1261 1254
1262 if (serial_paranoia_check(info, tty->name, "rs_write_room")) 1255 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1263 return 0; 1256 return 0;
1264 1257
@@ -1273,8 +1266,8 @@ static int rs_write_room(struct tty_struct *tty)
1273 1266
1274static int rs_chars_in_buffer(struct tty_struct *tty) 1267static int rs_chars_in_buffer(struct tty_struct *tty)
1275{ 1268{
1276 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1269 struct esp_struct *info = tty->driver_data;
1277 1270
1278 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) 1271 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1279 return 0; 1272 return 0;
1280 return info->xmit_cnt; 1273 return info->xmit_cnt;
@@ -1282,9 +1275,9 @@ static int rs_chars_in_buffer(struct tty_struct *tty)
1282 1275
1283static void rs_flush_buffer(struct tty_struct *tty) 1276static void rs_flush_buffer(struct tty_struct *tty)
1284{ 1277{
1285 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1278 struct esp_struct *info = tty->driver_data;
1286 unsigned long flags; 1279 unsigned long flags;
1287 1280
1288 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) 1281 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1289 return; 1282 return;
1290 spin_lock_irqsave(&info->lock, flags); 1283 spin_lock_irqsave(&info->lock, flags);
@@ -1296,20 +1289,20 @@ static void rs_flush_buffer(struct tty_struct *tty)
1296/* 1289/*
1297 * ------------------------------------------------------------ 1290 * ------------------------------------------------------------
1298 * rs_throttle() 1291 * rs_throttle()
1299 * 1292 *
1300 * 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
1301 * incoming characters should be throttled. 1294 * incoming characters should be throttled.
1302 * ------------------------------------------------------------ 1295 * ------------------------------------------------------------
1303 */ 1296 */
1304static void rs_throttle(struct tty_struct * tty) 1297static void rs_throttle(struct tty_struct *tty)
1305{ 1298{
1306 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1299 struct esp_struct *info = tty->driver_data;
1307 unsigned long flags; 1300 unsigned long flags;
1308#ifdef SERIAL_DEBUG_THROTTLE 1301#ifdef SERIAL_DEBUG_THROTTLE
1309 char buf[64]; 1302 char buf[64];
1310 1303
1311 printk("throttle %s: %d....\n", tty_name(tty, buf), 1304 printk("throttle %s: %d....\n", tty_name(tty, buf),
1312 tty->ldisc.chars_in_buffer(tty)); 1305 tty_chars_in_buffer(tty));
1313#endif 1306#endif
1314 1307
1315 if (serial_paranoia_check(info, tty->name, "rs_throttle")) 1308 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
@@ -1324,20 +1317,20 @@ static void rs_throttle(struct tty_struct * tty)
1324 spin_unlock_irqrestore(&info->lock, flags); 1317 spin_unlock_irqrestore(&info->lock, flags);
1325} 1318}
1326 1319
1327static void rs_unthrottle(struct tty_struct * tty) 1320static void rs_unthrottle(struct tty_struct *tty)
1328{ 1321{
1329 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1322 struct esp_struct *info = tty->driver_data;
1330 unsigned long flags; 1323 unsigned long flags;
1331#ifdef SERIAL_DEBUG_THROTTLE 1324#ifdef SERIAL_DEBUG_THROTTLE
1332 char buf[64]; 1325 char buf[64];
1333 1326
1334 printk("unthrottle %s: %d....\n", tty_name(tty, buf), 1327 printk(KERN_DEBUG "unthrottle %s: %d....\n", tty_name(tty, buf),
1335 tty->ldisc.chars_in_buffer(tty)); 1328 tty_chars_in_buffer(tty));
1336#endif 1329#endif
1337 1330
1338 if (serial_paranoia_check(info, tty->name, "rs_unthrottle")) 1331 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1339 return; 1332 return;
1340 1333
1341 spin_lock_irqsave(&info->lock, flags); 1334 spin_lock_irqsave(&info->lock, flags);
1342 info->IER |= UART_IER_RDI; 1335 info->IER |= UART_IER_RDI;
1343 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 1336 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
@@ -1353,11 +1346,11 @@ static void rs_unthrottle(struct tty_struct * tty)
1353 * ------------------------------------------------------------ 1346 * ------------------------------------------------------------
1354 */ 1347 */
1355 1348
1356static int get_serial_info(struct esp_struct * info, 1349static int get_serial_info(struct esp_struct *info,
1357 struct serial_struct __user *retinfo) 1350 struct serial_struct __user *retinfo)
1358{ 1351{
1359 struct serial_struct tmp; 1352 struct serial_struct tmp;
1360 1353
1361 lock_kernel(); 1354 lock_kernel();
1362 memset(&tmp, 0, sizeof(tmp)); 1355 memset(&tmp, 0, sizeof(tmp));
1363 tmp.type = PORT_16550A; 1356 tmp.type = PORT_16550A;
@@ -1372,16 +1365,16 @@ static int get_serial_info(struct esp_struct * info,
1372 tmp.custom_divisor = info->custom_divisor; 1365 tmp.custom_divisor = info->custom_divisor;
1373 tmp.hub6 = 0; 1366 tmp.hub6 = 0;
1374 unlock_kernel(); 1367 unlock_kernel();
1375 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1368 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1376 return -EFAULT; 1369 return -EFAULT;
1377 return 0; 1370 return 0;
1378} 1371}
1379 1372
1380static int get_esp_config(struct esp_struct * info, 1373static int get_esp_config(struct esp_struct *info,
1381 struct hayes_esp_config __user *retinfo) 1374 struct hayes_esp_config __user *retinfo)
1382{ 1375{
1383 struct hayes_esp_config tmp; 1376 struct hayes_esp_config tmp;
1384 1377
1385 if (!retinfo) 1378 if (!retinfo)
1386 return -EFAULT; 1379 return -EFAULT;
1387 1380
@@ -1399,7 +1392,7 @@ static int get_esp_config(struct esp_struct * info,
1399 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; 1392 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
1400} 1393}
1401 1394
1402static int set_serial_info(struct esp_struct * info, 1395static int set_serial_info(struct esp_struct *info,
1403 struct serial_struct __user *new_info) 1396 struct serial_struct __user *new_info)
1404{ 1397{
1405 struct serial_struct new_serial; 1398 struct serial_struct new_serial;
@@ -1408,7 +1401,7 @@ static int set_serial_info(struct esp_struct * info,
1408 int retval = 0; 1401 int retval = 0;
1409 struct esp_struct *current_async; 1402 struct esp_struct *current_async;
1410 1403
1411 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1404 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1412 return -EFAULT; 1405 return -EFAULT;
1413 old_info = *info; 1406 old_info = *info;
1414 1407
@@ -1429,7 +1422,7 @@ static int set_serial_info(struct esp_struct * info,
1429 return -EINVAL; 1422 return -EINVAL;
1430 1423
1431 if (!capable(CAP_SYS_ADMIN)) { 1424 if (!capable(CAP_SYS_ADMIN)) {
1432 if (change_irq || 1425 if (change_irq ||
1433 (new_serial.close_delay != info->close_delay) || 1426 (new_serial.close_delay != info->close_delay) ||
1434 ((new_serial.flags & ~ASYNC_USR_MASK) != 1427 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1435 (info->flags & ~ASYNC_USR_MASK))) 1428 (info->flags & ~ASYNC_USR_MASK)))
@@ -1514,8 +1507,8 @@ static int set_serial_info(struct esp_struct * info,
1514 return retval; 1507 return retval;
1515} 1508}
1516 1509
1517static int set_esp_config(struct esp_struct * info, 1510static int set_esp_config(struct esp_struct *info,
1518 struct hayes_esp_config __user * new_info) 1511 struct hayes_esp_config __user *new_info)
1519{ 1512{
1520 struct hayes_esp_config new_config; 1513 struct hayes_esp_config new_config;
1521 unsigned int change_dma; 1514 unsigned int change_dma;
@@ -1557,7 +1550,6 @@ static int set_esp_config(struct esp_struct * info,
1557 if (new_config.dma_channel) { 1550 if (new_config.dma_channel) {
1558 /* PIO mode to DMA mode transition OR */ 1551 /* PIO mode to DMA mode transition OR */
1559 /* change current DMA channel */ 1552 /* change current DMA channel */
1560
1561 current_async = ports; 1553 current_async = ports;
1562 1554
1563 while (current_async) { 1555 while (current_async) {
@@ -1566,16 +1558,15 @@ static int set_esp_config(struct esp_struct * info,
1566 return -EBUSY; 1558 return -EBUSY;
1567 } else if (current_async->count) 1559 } else if (current_async->count)
1568 return -EBUSY; 1560 return -EBUSY;
1569 1561
1570 current_async = 1562 current_async = current_async->next_port;
1571 current_async->next_port;
1572 } 1563 }
1573 1564
1574 shutdown(info); 1565 shutdown(info);
1575 dma = new_config.dma_channel; 1566 dma = new_config.dma_channel;
1576 info->stat_flags &= ~ESP_STAT_NEVER_DMA; 1567 info->stat_flags &= ~ESP_STAT_NEVER_DMA;
1577 1568
1578 /* all ports must use the same DMA channel */ 1569 /* all ports must use the same DMA channel */
1579 1570
1580 spin_lock_irqsave(&info->lock, flags); 1571 spin_lock_irqsave(&info->lock, flags);
1581 current_async = ports; 1572 current_async = ports;
@@ -1587,7 +1578,6 @@ static int set_esp_config(struct esp_struct * info,
1587 spin_unlock_irqrestore(&info->lock, flags); 1578 spin_unlock_irqrestore(&info->lock, flags);
1588 } else { 1579 } else {
1589 /* DMA mode to PIO mode only */ 1580 /* DMA mode to PIO mode only */
1590
1591 if (info->count > 1) 1581 if (info->count > 1)
1592 return -EBUSY; 1582 return -EBUSY;
1593 1583
@@ -1658,9 +1648,9 @@ static int set_esp_config(struct esp_struct * info,
1658 * release the bus after transmitting. This must be done when 1648 * release the bus after transmitting. This must be done when
1659 * the transmit shift register is empty, not be done when the 1649 * the transmit shift register is empty, not be done when the
1660 * transmit holding register is empty. This functionality 1650 * transmit holding register is empty. This functionality
1661 * allows an RS485 driver to be written in user space. 1651 * allows an RS485 driver to be written in user space.
1662 */ 1652 */
1663static int get_lsr_info(struct esp_struct * info, unsigned int __user *value) 1653static int get_lsr_info(struct esp_struct *info, unsigned int __user *value)
1664{ 1654{
1665 unsigned char status; 1655 unsigned char status;
1666 unsigned int result; 1656 unsigned int result;
@@ -1671,13 +1661,13 @@ static int get_lsr_info(struct esp_struct * info, unsigned int __user *value)
1671 status = serial_in(info, UART_ESI_STAT1); 1661 status = serial_in(info, UART_ESI_STAT1);
1672 spin_unlock_irqrestore(&info->lock, flags); 1662 spin_unlock_irqrestore(&info->lock, flags);
1673 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0); 1663 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1674 return put_user(result,value); 1664 return put_user(result, value);
1675} 1665}
1676 1666
1677 1667
1678static int esp_tiocmget(struct tty_struct *tty, struct file *file) 1668static int esp_tiocmget(struct tty_struct *tty, struct file *file)
1679{ 1669{
1680 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1670 struct esp_struct *info = tty->driver_data;
1681 unsigned char control, status; 1671 unsigned char control, status;
1682 unsigned long flags; 1672 unsigned long flags;
1683 1673
@@ -1704,7 +1694,7 @@ static int esp_tiocmget(struct tty_struct *tty, struct file *file)
1704static int esp_tiocmset(struct tty_struct *tty, struct file *file, 1694static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1705 unsigned int set, unsigned int clear) 1695 unsigned int set, unsigned int clear)
1706{ 1696{
1707 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1697 struct esp_struct *info = tty->driver_data;
1708 unsigned long flags; 1698 unsigned long flags;
1709 1699
1710 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 1700 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
@@ -1737,9 +1727,9 @@ static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1737 */ 1727 */
1738static void esp_break(struct tty_struct *tty, int break_state) 1728static void esp_break(struct tty_struct *tty, int break_state)
1739{ 1729{
1740 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1730 struct esp_struct *info = tty->driver_data;
1741 unsigned long flags; 1731 unsigned long flags;
1742 1732
1743 if (serial_paranoia_check(info, tty->name, "esp_break")) 1733 if (serial_paranoia_check(info, tty->name, "esp_break"))
1744 return; 1734 return;
1745 1735
@@ -1759,10 +1749,10 @@ static void esp_break(struct tty_struct *tty, int break_state)
1759 } 1749 }
1760} 1750}
1761 1751
1762static int rs_ioctl(struct tty_struct *tty, struct file * file, 1752static int rs_ioctl(struct tty_struct *tty, struct file *file,
1763 unsigned int cmd, unsigned long arg) 1753 unsigned int cmd, unsigned long arg)
1764{ 1754{
1765 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1755 struct esp_struct *info = tty->driver_data;
1766 struct async_icount cprev, cnow; /* kernel counter temps */ 1756 struct async_icount cprev, cnow; /* kernel counter temps */
1767 struct serial_icounter_struct __user *p_cuser; /* user space */ 1757 struct serial_icounter_struct __user *p_cuser; /* user space */
1768 void __user *argp = (void __user *)arg; 1758 void __user *argp = (void __user *)arg;
@@ -1780,102 +1770,93 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1780 if (tty->flags & (1 << TTY_IO_ERROR)) 1770 if (tty->flags & (1 << TTY_IO_ERROR))
1781 return -EIO; 1771 return -EIO;
1782 } 1772 }
1783
1784 switch (cmd) {
1785 case TIOCGSERIAL:
1786 return get_serial_info(info, argp);
1787 case TIOCSSERIAL:
1788 lock_kernel();
1789 ret = set_serial_info(info, argp);
1790 unlock_kernel();
1791 return ret;
1792 case TIOCSERCONFIG:
1793 /* do not reconfigure after initial configuration */
1794 return 0;
1795
1796 case TIOCSERGWILD:
1797 return put_user(0L, (unsigned long __user *)argp);
1798 1773
1799 case TIOCSERGETLSR: /* Get line status register */ 1774 switch (cmd) {
1800 return get_lsr_info(info, argp); 1775 case TIOCGSERIAL:
1801 1776 return get_serial_info(info, argp);
1802 case TIOCSERSWILD: 1777 case TIOCSSERIAL:
1803 if (!capable(CAP_SYS_ADMIN)) 1778 lock_kernel();
1804 return -EPERM; 1779 ret = set_serial_info(info, argp);
1805 return 0; 1780 unlock_kernel();
1806 1781 return ret;
1807 /* 1782 case TIOCSERGWILD:
1808 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 1783 return put_user(0L, (unsigned long __user *)argp);
1809 * - mask passed in arg for lines of interest 1784 case TIOCSERGETLSR: /* Get line status register */
1810 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 1785 return get_lsr_info(info, argp);
1811 * Caller should use TIOCGICOUNT to see which one it was 1786 case TIOCSERSWILD:
1812 */ 1787 if (!capable(CAP_SYS_ADMIN))
1813 case TIOCMIWAIT: 1788 return -EPERM;
1789 return 0;
1790 /*
1791 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1792 * - mask passed in arg for lines of interest
1793 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1794 * Caller should use TIOCGICOUNT to see which one it was
1795 */
1796 case TIOCMIWAIT:
1797 spin_lock_irqsave(&info->lock, flags);
1798 cprev = info->icount; /* note the counters on entry */
1799 spin_unlock_irqrestore(&info->lock, flags);
1800 while (1) {
1801 /* FIXME: convert to new style wakeup */
1802 interruptible_sleep_on(&info->delta_msr_wait);
1803 /* see if a signal did it */
1804 if (signal_pending(current))
1805 return -ERESTARTSYS;
1814 spin_lock_irqsave(&info->lock, flags); 1806 spin_lock_irqsave(&info->lock, flags);
1815 cprev = info->icount; /* note the counters on entry */ 1807 cnow = info->icount; /* atomic copy */
1816 spin_unlock_irqrestore(&info->lock, flags); 1808 spin_unlock_irqrestore(&info->lock, flags);
1817 while (1) { 1809 if (cnow.rng == cprev.rng &&
1818 /* FIXME: convert to new style wakeup */ 1810 cnow.dsr == cprev.dsr &&
1819 interruptible_sleep_on(&info->delta_msr_wait); 1811 cnow.dcd == cprev.dcd &&
1820 /* see if a signal did it */ 1812 cnow.cts == cprev.cts)
1821 if (signal_pending(current)) 1813 return -EIO; /* no change => error */
1822 return -ERESTARTSYS; 1814 if (((arg & TIOCM_RNG) &&
1823 spin_lock_irqsave(&info->lock, flags); 1815 (cnow.rng != cprev.rng)) ||
1824 cnow = info->icount; /* atomic copy */ 1816 ((arg & TIOCM_DSR) &&
1825 spin_unlock_irqrestore(&info->lock, flags); 1817 (cnow.dsr != cprev.dsr)) ||
1826 if (cnow.rng == cprev.rng && 1818 ((arg & TIOCM_CD) &&
1827 cnow.dsr == cprev.dsr && 1819 (cnow.dcd != cprev.dcd)) ||
1828 cnow.dcd == cprev.dcd && 1820 ((arg & TIOCM_CTS) &&
1829 cnow.cts == cprev.cts) 1821 (cnow.cts != cprev.cts))) {
1830 return -EIO; /* no change => error */ 1822 return 0;
1831 if (((arg & TIOCM_RNG) &&
1832 (cnow.rng != cprev.rng)) ||
1833 ((arg & TIOCM_DSR) &&
1834 (cnow.dsr != cprev.dsr)) ||
1835 ((arg & TIOCM_CD) &&
1836 (cnow.dcd != cprev.dcd)) ||
1837 ((arg & TIOCM_CTS) &&
1838 (cnow.cts != cprev.cts)) ) {
1839 return 0;
1840 }
1841 cprev = cnow;
1842 } 1823 }
1843 /* NOTREACHED */ 1824 cprev = cnow;
1844
1845 /*
1846 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1847 * Return: write counters to the user passed counter struct
1848 * NB: both 1->0 and 0->1 transitions are counted except for
1849 * RI where only 0->1 is counted.
1850 */
1851 case TIOCGICOUNT:
1852 spin_lock_irqsave(&info->lock, flags);
1853 cnow = info->icount;
1854 spin_unlock_irqrestore(&info->lock, flags);
1855 p_cuser = argp;
1856 if (put_user(cnow.cts, &p_cuser->cts) ||
1857 put_user(cnow.dsr, &p_cuser->dsr) ||
1858 put_user(cnow.rng, &p_cuser->rng) ||
1859 put_user(cnow.dcd, &p_cuser->dcd))
1860 return -EFAULT;
1861
1862 return 0;
1863 case TIOCGHAYESESP:
1864 return get_esp_config(info, argp);
1865 case TIOCSHAYESESP:
1866 lock_kernel();
1867 ret = set_esp_config(info, argp);
1868 unlock_kernel();
1869 return ret;
1870 default:
1871 return -ENOIOCTLCMD;
1872 } 1825 }
1826 /* NOTREACHED */
1827 /*
1828 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1829 * Return: write counters to the user passed counter struct
1830 * NB: both 1->0 and 0->1 transitions are counted except for
1831 * RI where only 0->1 is counted.
1832 */
1833 case TIOCGICOUNT:
1834 spin_lock_irqsave(&info->lock, flags);
1835 cnow = info->icount;
1836 spin_unlock_irqrestore(&info->lock, flags);
1837 p_cuser = argp;
1838 if (put_user(cnow.cts, &p_cuser->cts) ||
1839 put_user(cnow.dsr, &p_cuser->dsr) ||
1840 put_user(cnow.rng, &p_cuser->rng) ||
1841 put_user(cnow.dcd, &p_cuser->dcd))
1842 return -EFAULT;
1843 return 0;
1844 case TIOCGHAYESESP:
1845 return get_esp_config(info, argp);
1846 case TIOCSHAYESESP:
1847 lock_kernel();
1848 ret = set_esp_config(info, argp);
1849 unlock_kernel();
1850 return ret;
1851 default:
1852 return -ENOIOCTLCMD;
1853 }
1873 return 0; 1854 return 0;
1874} 1855}
1875 1856
1876static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1857static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1877{ 1858{
1878 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1859 struct esp_struct *info = tty->driver_data;
1879 unsigned long flags; 1860 unsigned long flags;
1880 1861
1881 change_speed(info); 1862 change_speed(info);
@@ -1912,32 +1893,33 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1912/* 1893/*
1913 * ------------------------------------------------------------ 1894 * ------------------------------------------------------------
1914 * rs_close() 1895 * rs_close()
1915 * 1896 *
1916 * 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
1917 * 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
1918 * async structure from the interrupt chain if necessary, and we free 1899 * async structure from the interrupt chain if necessary, and we free
1919 * that IRQ if nothing is left in the chain. 1900 * that IRQ if nothing is left in the chain.
1920 * ------------------------------------------------------------ 1901 * ------------------------------------------------------------
1921 */ 1902 */
1922static void rs_close(struct tty_struct *tty, struct file * filp) 1903static void rs_close(struct tty_struct *tty, struct file *filp)
1923{ 1904{
1924 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1905 struct esp_struct *info = tty->driver_data;
1925 unsigned long flags; 1906 unsigned long flags;
1926 1907
1927 if (!info || serial_paranoia_check(info, tty->name, "rs_close")) 1908 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1928 return; 1909 return;
1929 1910
1930 spin_lock_irqsave(&info->lock, flags); 1911 spin_lock_irqsave(&info->lock, flags);
1931 1912
1932 if (tty_hung_up_p(filp)) { 1913 if (tty_hung_up_p(filp)) {
1933 DBG_CNT("before DEC-hung"); 1914 DBG_CNT("before DEC-hung");
1934 goto out; 1915 goto out;
1935 } 1916 }
1936 1917
1937#ifdef SERIAL_DEBUG_OPEN 1918#ifdef SERIAL_DEBUG_OPEN
1938 printk("rs_close ttys%d, count = %d\n", info->line, info->count); 1919 printk(KERN_DEBUG "rs_close ttys%d, count = %d\n",
1920 info->line, info->count);
1939#endif 1921#endif
1940 if ((tty->count == 1) && (info->count != 1)) { 1922 if (tty->count == 1 && info->count != 1) {
1941 /* 1923 /*
1942 * Uh, oh. tty->count is 1, which means that the tty 1924 * Uh, oh. tty->count is 1, which means that the tty
1943 * structure will be freed. Info->count should always 1925 * structure will be freed. Info->count should always
@@ -1945,12 +1927,11 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1945 * one, we've got real problems, since it means the 1927 * one, we've got real problems, since it means the
1946 * serial port won't be shutdown. 1928 * serial port won't be shutdown.
1947 */ 1929 */
1948 printk("rs_close: bad serial port count; tty->count is 1, " 1930 printk(KERN_DEBUG "rs_close: bad serial port count; tty->count is 1, info->count is %d\n", info->count);
1949 "info->count is %d\n", info->count);
1950 info->count = 1; 1931 info->count = 1;
1951 } 1932 }
1952 if (--info->count < 0) { 1933 if (--info->count < 0) {
1953 printk("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",
1954 info->line, info->count); 1935 info->line, info->count);
1955 info->count = 0; 1936 info->count = 0;
1956 } 1937 }
@@ -1962,7 +1943,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1962 1943
1963 spin_unlock_irqrestore(&info->lock, flags); 1944 spin_unlock_irqrestore(&info->lock, flags);
1964 /* 1945 /*
1965 * 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
1966 * the line discipline to only process XON/XOFF characters. 1947 * the line discipline to only process XON/XOFF characters.
1967 */ 1948 */
1968 tty->closing = 1; 1949 tty->closing = 1;
@@ -2003,9 +1984,8 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
2003 info->tty = NULL; 1984 info->tty = NULL;
2004 1985
2005 if (info->blocked_open) { 1986 if (info->blocked_open) {
2006 if (info->close_delay) { 1987 if (info->close_delay)
2007 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1988 msleep_interruptible(jiffies_to_msecs(info->close_delay));
2008 }
2009 wake_up_interruptible(&info->open_wait); 1989 wake_up_interruptible(&info->open_wait);
2010 } 1990 }
2011 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1991 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -2018,7 +1998,7 @@ out:
2018 1998
2019static void rs_wait_until_sent(struct tty_struct *tty, int timeout) 1999static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2020{ 2000{
2021 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 2001 struct esp_struct *info = tty->driver_data;
2022 unsigned long orig_jiffies, char_time; 2002 unsigned long orig_jiffies, char_time;
2023 unsigned long flags; 2003 unsigned long flags;
2024 2004
@@ -2060,11 +2040,11 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2060 */ 2040 */
2061static void esp_hangup(struct tty_struct *tty) 2041static void esp_hangup(struct tty_struct *tty)
2062{ 2042{
2063 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 2043 struct esp_struct *info = tty->driver_data;
2064 2044
2065 if (serial_paranoia_check(info, tty->name, "esp_hangup")) 2045 if (serial_paranoia_check(info, tty->name, "esp_hangup"))
2066 return; 2046 return;
2067 2047
2068 rs_flush_buffer(tty); 2048 rs_flush_buffer(tty);
2069 shutdown(info); 2049 shutdown(info);
2070 info->count = 0; 2050 info->count = 0;
@@ -2078,7 +2058,7 @@ static void esp_hangup(struct tty_struct *tty)
2078 * esp_open() and friends 2058 * esp_open() and friends
2079 * ------------------------------------------------------------ 2059 * ------------------------------------------------------------
2080 */ 2060 */
2081static int block_til_ready(struct tty_struct *tty, struct file * filp, 2061static int block_til_ready(struct tty_struct *tty, struct file *filp,
2082 struct esp_struct *info) 2062 struct esp_struct *info)
2083{ 2063{
2084 DECLARE_WAITQUEUE(wait, current); 2064 DECLARE_WAITQUEUE(wait, current);
@@ -2127,11 +2107,11 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2127 retval = 0; 2107 retval = 0;
2128 add_wait_queue(&info->open_wait, &wait); 2108 add_wait_queue(&info->open_wait, &wait);
2129#ifdef SERIAL_DEBUG_OPEN 2109#ifdef SERIAL_DEBUG_OPEN
2130 printk("block_til_ready before block: ttys%d, count = %d\n", 2110 printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n",
2131 info->line, info->count); 2111 info->line, info->count);
2132#endif 2112#endif
2133 spin_lock_irqsave(&info->lock, flags); 2113 spin_lock_irqsave(&info->lock, flags);
2134 if (!tty_hung_up_p(filp)) 2114 if (!tty_hung_up_p(filp))
2135 info->count--; 2115 info->count--;
2136 info->blocked_open++; 2116 info->blocked_open++;
2137 while (1) { 2117 while (1) {
@@ -2153,7 +2133,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2153 if (info->flags & ASYNC_HUP_NOTIFY) 2133 if (info->flags & ASYNC_HUP_NOTIFY)
2154 retval = -EAGAIN; 2134 retval = -EAGAIN;
2155 else 2135 else
2156 retval = -ERESTARTSYS; 2136 retval = -ERESTARTSYS;
2157#else 2137#else
2158 retval = -EAGAIN; 2138 retval = -EAGAIN;
2159#endif 2139#endif
@@ -2172,7 +2152,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2172 break; 2152 break;
2173 } 2153 }
2174#ifdef SERIAL_DEBUG_OPEN 2154#ifdef SERIAL_DEBUG_OPEN
2175 printk("block_til_ready blocking: ttys%d, count = %d\n", 2155 printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n",
2176 info->line, info->count); 2156 info->line, info->count);
2177#endif 2157#endif
2178 spin_unlock_irqrestore(&info->lock, flags); 2158 spin_unlock_irqrestore(&info->lock, flags);
@@ -2186,14 +2166,14 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2186 info->blocked_open--; 2166 info->blocked_open--;
2187 spin_unlock_irqrestore(&info->lock, flags); 2167 spin_unlock_irqrestore(&info->lock, flags);
2188#ifdef SERIAL_DEBUG_OPEN 2168#ifdef SERIAL_DEBUG_OPEN
2189 printk("block_til_ready after blocking: ttys%d, count = %d\n", 2169 printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n",
2190 info->line, info->count); 2170 info->line, info->count);
2191#endif 2171#endif
2192 if (retval) 2172 if (retval)
2193 return retval; 2173 return retval;
2194 info->flags |= ASYNC_NORMAL_ACTIVE; 2174 info->flags |= ASYNC_NORMAL_ACTIVE;
2195 return 0; 2175 return 0;
2196} 2176}
2197 2177
2198/* 2178/*
2199 * This routine is called whenever a serial port is opened. It 2179 * This routine is called whenever a serial port is opened. It
@@ -2201,7 +2181,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2201 * the IRQ chain. It also performs the serial-specific 2181 * the IRQ chain. It also performs the serial-specific
2202 * initialization for the tty structure. 2182 * initialization for the tty structure.
2203 */ 2183 */
2204static int esp_open(struct tty_struct *tty, struct file * filp) 2184static int esp_open(struct tty_struct *tty, struct file *filp)
2205{ 2185{
2206 struct esp_struct *info; 2186 struct esp_struct *info;
2207 int retval, line; 2187 int retval, line;
@@ -2224,7 +2204,7 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2224 } 2204 }
2225 2205
2226#ifdef SERIAL_DEBUG_OPEN 2206#ifdef SERIAL_DEBUG_OPEN
2227 printk("esp_open %s, count = %d\n", tty->name, info->count); 2207 printk(KERN_DEBUG "esp_open %s, count = %d\n", tty->name, info->count);
2228#endif 2208#endif
2229 spin_lock_irqsave(&info->lock, flags); 2209 spin_lock_irqsave(&info->lock, flags);
2230 info->count++; 2210 info->count++;
@@ -2232,7 +2212,7 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2232 info->tty = tty; 2212 info->tty = tty;
2233 2213
2234 spin_unlock_irqrestore(&info->lock, flags); 2214 spin_unlock_irqrestore(&info->lock, flags);
2235 2215
2236 /* 2216 /*
2237 * Start up serial port 2217 * Start up serial port
2238 */ 2218 */
@@ -2243,14 +2223,13 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2243 retval = block_til_ready(tty, filp, info); 2223 retval = block_til_ready(tty, filp, info);
2244 if (retval) { 2224 if (retval) {
2245#ifdef SERIAL_DEBUG_OPEN 2225#ifdef SERIAL_DEBUG_OPEN
2246 printk("esp_open returning after block_til_ready with %d\n", 2226 printk(KERN_DEBUG "esp_open returning after block_til_ready with %d\n",
2247 retval); 2227 retval);
2248#endif 2228#endif
2249 return retval; 2229 return retval;
2250 } 2230 }
2251
2252#ifdef SERIAL_DEBUG_OPEN 2231#ifdef SERIAL_DEBUG_OPEN
2253 printk("esp_open %s successful...", tty->name); 2232 printk(KERN_DEBUG "esp_open %s successful...", tty->name);
2254#endif 2233#endif
2255 return 0; 2234 return 0;
2256} 2235}
@@ -2268,10 +2247,10 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2268 * number, and identifies which options were configured into this 2247 * number, and identifies which options were configured into this
2269 * driver. 2248 * driver.
2270 */ 2249 */
2271 2250
2272static inline void show_serial_version(void) 2251static void show_serial_version(void)
2273{ 2252{
2274 printk(KERN_INFO "%s version %s (DMA %u)\n", 2253 printk(KERN_INFO "%s version %s (DMA %u)\n",
2275 serial_name, serial_version, dma); 2254 serial_name, serial_version, dma);
2276} 2255}
2277 2256
@@ -2279,7 +2258,7 @@ static inline void show_serial_version(void)
2279 * 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
2280 * port. 2259 * port.
2281 */ 2260 */
2282static inline int autoconfig(struct esp_struct * info) 2261static int autoconfig(struct esp_struct *info)
2283{ 2262{
2284 int port_detected = 0; 2263 int port_detected = 0;
2285 unsigned long flags; 2264 unsigned long flags;
@@ -2355,14 +2334,14 @@ static const struct tty_operations esp_ops = {
2355static int __init espserial_init(void) 2334static int __init espserial_init(void)
2356{ 2335{
2357 int i, offset; 2336 int i, offset;
2358 struct esp_struct * info; 2337 struct esp_struct *info;
2359 struct esp_struct *last_primary = NULL; 2338 struct esp_struct *last_primary = NULL;
2360 int esp[] = {0x100,0x140,0x180,0x200,0x240,0x280,0x300,0x380}; 2339 int esp[] = { 0x100, 0x140, 0x180, 0x200, 0x240, 0x280, 0x300, 0x380 };
2361 2340
2362 esp_driver = alloc_tty_driver(NR_PORTS); 2341 esp_driver = alloc_tty_driver(NR_PORTS);
2363 if (!esp_driver) 2342 if (!esp_driver)
2364 return -ENOMEM; 2343 return -ENOMEM;
2365 2344
2366 for (i = 0; i < NR_PRIMARY; i++) { 2345 for (i = 0; i < NR_PRIMARY; i++) {
2367 if (irq[i] != 0) { 2346 if (irq[i] != 0) {
2368 if ((irq[i] < 2) || (irq[i] > 15) || (irq[i] == 6) || 2347 if ((irq[i] < 2) || (irq[i] > 15) || (irq[i] == 6) ||
@@ -2384,20 +2363,20 @@ static int __init espserial_init(void)
2384 2363
2385 if ((flow_off < 1) || (flow_off > 1023)) 2364 if ((flow_off < 1) || (flow_off > 1023))
2386 flow_off = 1016; 2365 flow_off = 1016;
2387 2366
2388 if ((flow_on < 1) || (flow_on > 1023)) 2367 if ((flow_on < 1) || (flow_on > 1023))
2389 flow_on = 944; 2368 flow_on = 944;
2390 2369
2391 if ((rx_timeout < 0) || (rx_timeout > 255)) 2370 if ((rx_timeout < 0) || (rx_timeout > 255))
2392 rx_timeout = 128; 2371 rx_timeout = 128;
2393 2372
2394 if (flow_on >= flow_off) 2373 if (flow_on >= flow_off)
2395 flow_on = flow_off - 1; 2374 flow_on = flow_off - 1;
2396 2375
2397 show_serial_version(); 2376 show_serial_version();
2398 2377
2399 /* Initialize the tty_driver structure */ 2378 /* Initialize the tty_driver structure */
2400 2379
2401 esp_driver->owner = THIS_MODULE; 2380 esp_driver->owner = THIS_MODULE;
2402 esp_driver->name = "ttyP"; 2381 esp_driver->name = "ttyP";
2403 esp_driver->major = ESP_IN_MAJOR; 2382 esp_driver->major = ESP_IN_MAJOR;
@@ -2407,10 +2386,11 @@ static int __init espserial_init(void)
2407 esp_driver->init_termios = tty_std_termios; 2386 esp_driver->init_termios = tty_std_termios;
2408 esp_driver->init_termios.c_cflag = 2387 esp_driver->init_termios.c_cflag =
2409 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2388 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2389 esp_driver->init_termios.c_ispeed = 9600;
2390 esp_driver->init_termios.c_ospeed = 9600;
2410 esp_driver->flags = TTY_DRIVER_REAL_RAW; 2391 esp_driver->flags = TTY_DRIVER_REAL_RAW;
2411 tty_set_operations(esp_driver, &esp_ops); 2392 tty_set_operations(esp_driver, &esp_ops);
2412 if (tty_register_driver(esp_driver)) 2393 if (tty_register_driver(esp_driver)) {
2413 {
2414 printk(KERN_ERR "Couldn't register esp serial driver"); 2394 printk(KERN_ERR "Couldn't register esp serial driver");
2415 put_tty_driver(esp_driver); 2395 put_tty_driver(esp_driver);
2416 return 1; 2396 return 1;
@@ -2418,8 +2398,7 @@ static int __init espserial_init(void)
2418 2398
2419 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL); 2399 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2420 2400
2421 if (!info) 2401 if (!info) {
2422 {
2423 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");
2424 tty_unregister_driver(esp_driver); 2403 tty_unregister_driver(esp_driver);
2425 put_tty_driver(esp_driver); 2404 put_tty_driver(esp_driver);
@@ -2482,10 +2461,8 @@ static int __init espserial_init(void)
2482 info->stat_flags |= ESP_STAT_NEVER_DMA; 2461 info->stat_flags |= ESP_STAT_NEVER_DMA;
2483 2462
2484 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL); 2463 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2485 if (!info) 2464 if (!info) {
2486 { 2465 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2487 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2488
2489 /* allow use of the already detected ports */ 2466 /* allow use of the already detected ports */
2490 return 0; 2467 return 0;
2491 } 2468 }
@@ -2509,22 +2486,20 @@ static int __init espserial_init(void)
2509 return 0; 2486 return 0;
2510} 2487}
2511 2488
2512static void __exit espserial_exit(void) 2489static void __exit espserial_exit(void)
2513{ 2490{
2514 int e1; 2491 int e1;
2515 struct esp_struct *temp_async; 2492 struct esp_struct *temp_async;
2516 struct esp_pio_buffer *pio_buf; 2493 struct esp_pio_buffer *pio_buf;
2517 2494
2518 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */ 2495 e1 = tty_unregister_driver(esp_driver);
2519 if ((e1 = tty_unregister_driver(esp_driver))) 2496 if (e1)
2520 printk("SERIAL: failed to unregister serial driver (%d)\n", 2497 printk(KERN_ERR "esp: failed to unregister driver (%d)\n", e1);
2521 e1);
2522 put_tty_driver(esp_driver); 2498 put_tty_driver(esp_driver);
2523 2499
2524 while (ports) { 2500 while (ports) {
2525 if (ports->port) { 2501 if (ports->port)
2526 release_region(ports->port, REGION_SIZE); 2502 release_region(ports->port, REGION_SIZE);
2527 }
2528 temp_async = ports->next_port; 2503 temp_async = ports->next_port;
2529 kfree(ports); 2504 kfree(ports);
2530 ports = temp_async; 2505 ports = temp_async;