aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial/68328serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty/serial/68328serial.c')
-rw-r--r--drivers/tty/serial/68328serial.c383
1 files changed, 152 insertions, 231 deletions
diff --git a/drivers/tty/serial/68328serial.c b/drivers/tty/serial/68328serial.c
index 5ce782529d65..3ed20e435e59 100644
--- a/drivers/tty/serial/68328serial.c
+++ b/drivers/tty/serial/68328serial.c
@@ -17,6 +17,7 @@
17#include <asm/dbg.h> 17#include <asm/dbg.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/serial.h>
20#include <linux/signal.h> 21#include <linux/signal.h>
21#include <linux/sched.h> 22#include <linux/sched.h>
22#include <linux/timer.h> 23#include <linux/timer.h>
@@ -56,8 +57,6 @@
56#endif /* CONFIG_M68VZ328 */ 57#endif /* CONFIG_M68VZ328 */
57#endif /* CONFIG_M68EZ328 */ 58#endif /* CONFIG_M68EZ328 */
58 59
59#include "68328serial.h"
60
61/* Turn off usage of real serial interrupt code, to "support" Copilot */ 60/* Turn off usage of real serial interrupt code, to "support" Copilot */
62#ifdef CONFIG_XCOPILOT_BUGS 61#ifdef CONFIG_XCOPILOT_BUGS
63#undef USE_INTS 62#undef USE_INTS
@@ -65,33 +64,82 @@
65#define USE_INTS 64#define USE_INTS
66#endif 65#endif
67 66
68static struct m68k_serial m68k_soft[NR_PORTS]; 67/*
68 * I believe this is the optimal setting that reduces the number of interrupts.
69 * At high speeds the output might become a little "bursted" (use USTCNT_TXHE
70 * if that bothers you), but in most cases it will not, since we try to
71 * transmit characters every time rs_interrupt is called. Thus, quite often
72 * you'll see that a receive interrupt occures before the transmit one.
73 * -- Vladimir Gurevich
74 */
75#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)
69 76
70static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS; 77/*
78 * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special
79 * "Old data interrupt" which occures whenever the data stay in the FIFO
80 * longer than 30 bits time. This allows us to use FIFO without compromising
81 * latency. '328 does not have this feature and without the real 328-based
82 * board I would assume that RXRE is the safest setting.
83 *
84 * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of
85 * interrupts. RXFE (receive queue full) causes the system to lose data
86 * at least at 115200 baud
87 *
88 * If your board is busy doing other stuff, you might consider to use
89 * RXRE (data ready intrrupt) instead.
90 *
91 * The other option is to make these INTR masks run-time configurable, so
92 * that people can dynamically adapt them according to the current usage.
93 * -- Vladimir Gurevich
94 */
71 95
72/* multiple ports are contiguous in memory */ 96/* (es) */
73m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR; 97#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)
98#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)
99#elif defined(CONFIG_M68328)
100#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)
101#else
102#error Please, define the Rx interrupt events for your CPU
103#endif
104/* (/es) */
74 105
75struct tty_struct m68k_ttys; 106/*
76struct m68k_serial *m68k_consinfo = 0; 107 * This is our internal structure for each serial port's state.
108 */
109struct m68k_serial {
110 struct tty_port tport;
111 char is_cons; /* Is this our console. */
112 int magic;
113 int baud_base;
114 int port;
115 int irq;
116 int type; /* UART type */
117 int custom_divisor;
118 int x_char; /* xon/xoff character */
119 int line;
120 unsigned char *xmit_buf;
121 int xmit_head;
122 int xmit_tail;
123 int xmit_cnt;
124};
77 125
78#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */ 126#define SERIAL_MAGIC 0x5301
79 127
80struct tty_driver *serial_driver; 128/*
129 * Define the number of ports supported and their irqs.
130 */
131#define NR_PORTS 1
81 132
82/* number of characters left in xmit buffer before we ask for more */ 133static struct m68k_serial m68k_soft[NR_PORTS];
83#define WAKEUP_CHARS 256
84 134
85/* Debugging... DEBUG_INTR is bad to use when one of the zs 135static unsigned int uart_irqs[NR_PORTS] = { UART_IRQ_NUM };
86 * lines is your console ;(
87 */
88#undef SERIAL_DEBUG_INTR
89#undef SERIAL_DEBUG_OPEN
90#undef SERIAL_DEBUG_FLOW
91 136
92#define RS_ISR_PASS_LIMIT 256 137/* multiple ports are contiguous in memory */
138m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR;
139
140struct tty_driver *serial_driver;
93 141
94static void change_speed(struct m68k_serial *info); 142static void change_speed(struct m68k_serial *info, struct tty_struct *tty);
95 143
96/* 144/*
97 * Setup for console. Argument comes from the boot command line. 145 * Setup for console. Argument comes from the boot command line.
@@ -143,17 +191,6 @@ static int baud_table[] = {
143 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 191 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
144 9600, 19200, 38400, 57600, 115200, 0 }; 192 9600, 19200, 38400, 57600, 115200, 0 };
145 193
146/* Sets or clears DTR/RTS on the requested line */
147static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)
148{
149 if (set) {
150 /* set the RTS/CTS line */
151 } else {
152 /* clear it */
153 }
154 return;
155}
156
157/* Utility routines */ 194/* Utility routines */
158static inline int get_baud(struct m68k_serial *ss) 195static inline int get_baud(struct m68k_serial *ss)
159{ 196{
@@ -189,7 +226,8 @@ static void rs_stop(struct tty_struct *tty)
189 226
190static int rs_put_char(char ch) 227static int rs_put_char(char ch)
191{ 228{
192 int flags, loops = 0; 229 unsigned long flags;
230 int loops = 0;
193 231
194 local_irq_save(flags); 232 local_irq_save(flags);
195 233
@@ -224,28 +262,9 @@ static void rs_start(struct tty_struct *tty)
224 local_irq_restore(flags); 262 local_irq_restore(flags);
225} 263}
226 264
227/* Drop into either the boot monitor or kadb upon receiving a break 265static void receive_chars(struct m68k_serial *info, struct tty_struct *tty,
228 * from keyboard/console input. 266 unsigned short rx)
229 */
230static void batten_down_hatches(void)
231{
232 /* Drop into the debugger */
233}
234
235static void status_handle(struct m68k_serial *info, unsigned short status)
236{ 267{
237 /* If this is console input and this is a
238 * 'break asserted' status change interrupt
239 * see if we can drop into the debugger
240 */
241 if((status & URX_BREAK) && info->break_abort)
242 batten_down_hatches();
243 return;
244}
245
246static void receive_chars(struct m68k_serial *info, unsigned short rx)
247{
248 struct tty_struct *tty = info->tty;
249 m68328_uart *uart = &uart_addr[info->line]; 268 m68328_uart *uart = &uart_addr[info->line];
250 unsigned char ch, flag; 269 unsigned char ch, flag;
251 270
@@ -259,7 +278,6 @@ static void receive_chars(struct m68k_serial *info, unsigned short rx)
259 278
260 if(info->is_cons) { 279 if(info->is_cons) {
261 if(URX_BREAK & rx) { /* whee, break received */ 280 if(URX_BREAK & rx) { /* whee, break received */
262 status_handle(info, rx);
263 return; 281 return;
264#ifdef CONFIG_MAGIC_SYSRQ 282#ifdef CONFIG_MAGIC_SYSRQ
265 } else if (ch == 0x10) { /* ^P */ 283 } else if (ch == 0x10) { /* ^P */
@@ -280,16 +298,13 @@ static void receive_chars(struct m68k_serial *info, unsigned short rx)
280 298
281 flag = TTY_NORMAL; 299 flag = TTY_NORMAL;
282 300
283 if(rx & URX_PARITY_ERROR) { 301 if (rx & URX_PARITY_ERROR)
284 flag = TTY_PARITY; 302 flag = TTY_PARITY;
285 status_handle(info, rx); 303 else if (rx & URX_OVRUN)
286 } else if(rx & URX_OVRUN) {
287 flag = TTY_OVERRUN; 304 flag = TTY_OVERRUN;
288 status_handle(info, rx); 305 else if (rx & URX_FRAME_ERROR)
289 } else if(rx & URX_FRAME_ERROR) {
290 flag = TTY_FRAME; 306 flag = TTY_FRAME;
291 status_handle(info, rx); 307
292 }
293 tty_insert_flip_char(tty, ch, flag); 308 tty_insert_flip_char(tty, ch, flag);
294#ifndef CONFIG_XCOPILOT_BUGS 309#ifndef CONFIG_XCOPILOT_BUGS
295 } while((rx = uart->urx.w) & URX_DATA_READY); 310 } while((rx = uart->urx.w) & URX_DATA_READY);
@@ -301,7 +316,7 @@ clear_and_exit:
301 return; 316 return;
302} 317}
303 318
304static void transmit_chars(struct m68k_serial *info) 319static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty)
305{ 320{
306 m68328_uart *uart = &uart_addr[info->line]; 321 m68328_uart *uart = &uart_addr[info->line];
307 322
@@ -312,7 +327,7 @@ static void transmit_chars(struct m68k_serial *info)
312 goto clear_and_return; 327 goto clear_and_return;
313 } 328 }
314 329
315 if((info->xmit_cnt <= 0) || info->tty->stopped) { 330 if ((info->xmit_cnt <= 0) || !tty || tty->stopped) {
316 /* That's peculiar... TX ints off */ 331 /* That's peculiar... TX ints off */
317 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 332 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
318 goto clear_and_return; 333 goto clear_and_return;
@@ -340,6 +355,7 @@ clear_and_return:
340irqreturn_t rs_interrupt(int irq, void *dev_id) 355irqreturn_t rs_interrupt(int irq, void *dev_id)
341{ 356{
342 struct m68k_serial *info = dev_id; 357 struct m68k_serial *info = dev_id;
358 struct tty_struct *tty = tty_port_tty_get(&info->tport);
343 m68328_uart *uart; 359 m68328_uart *uart;
344 unsigned short rx; 360 unsigned short rx;
345 unsigned short tx; 361 unsigned short tx;
@@ -350,20 +366,24 @@ irqreturn_t rs_interrupt(int irq, void *dev_id)
350#ifdef USE_INTS 366#ifdef USE_INTS
351 tx = uart->utx.w; 367 tx = uart->utx.w;
352 368
353 if (rx & URX_DATA_READY) receive_chars(info, rx); 369 if (rx & URX_DATA_READY)
354 if (tx & UTX_TX_AVAIL) transmit_chars(info); 370 receive_chars(info, tty, rx);
371 if (tx & UTX_TX_AVAIL)
372 transmit_chars(info, tty);
355#else 373#else
356 receive_chars(info, rx); 374 receive_chars(info, tty, rx);
357#endif 375#endif
376 tty_kref_put(tty);
377
358 return IRQ_HANDLED; 378 return IRQ_HANDLED;
359} 379}
360 380
361static int startup(struct m68k_serial * info) 381static int startup(struct m68k_serial *info, struct tty_struct *tty)
362{ 382{
363 m68328_uart *uart = &uart_addr[info->line]; 383 m68328_uart *uart = &uart_addr[info->line];
364 unsigned long flags; 384 unsigned long flags;
365 385
366 if (info->flags & S_INITIALIZED) 386 if (info->tport.flags & ASYNC_INITIALIZED)
367 return 0; 387 return 0;
368 388
369 if (!info->xmit_buf) { 389 if (!info->xmit_buf) {
@@ -380,7 +400,6 @@ static int startup(struct m68k_serial * info)
380 */ 400 */
381 401
382 uart->ustcnt = USTCNT_UEN; 402 uart->ustcnt = USTCNT_UEN;
383 info->xmit_fifo_size = 1;
384 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN; 403 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;
385 (void)uart->urx.w; 404 (void)uart->urx.w;
386 405
@@ -394,17 +413,17 @@ static int startup(struct m68k_serial * info)
394 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK; 413 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;
395#endif 414#endif
396 415
397 if (info->tty) 416 if (tty)
398 clear_bit(TTY_IO_ERROR, &info->tty->flags); 417 clear_bit(TTY_IO_ERROR, &tty->flags);
399 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 418 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
400 419
401 /* 420 /*
402 * and set the speed of the serial port 421 * and set the speed of the serial port
403 */ 422 */
404 423
405 change_speed(info); 424 change_speed(info, tty);
406 425
407 info->flags |= S_INITIALIZED; 426 info->tport.flags |= ASYNC_INITIALIZED;
408 local_irq_restore(flags); 427 local_irq_restore(flags);
409 return 0; 428 return 0;
410} 429}
@@ -413,13 +432,13 @@ static int startup(struct m68k_serial * info)
413 * This routine will shutdown a serial port; interrupts are disabled, and 432 * This routine will shutdown a serial port; interrupts are disabled, and
414 * DTR is dropped if the hangup on close termio flag is on. 433 * DTR is dropped if the hangup on close termio flag is on.
415 */ 434 */
416static void shutdown(struct m68k_serial * info) 435static void shutdown(struct m68k_serial *info, struct tty_struct *tty)
417{ 436{
418 m68328_uart *uart = &uart_addr[info->line]; 437 m68328_uart *uart = &uart_addr[info->line];
419 unsigned long flags; 438 unsigned long flags;
420 439
421 uart->ustcnt = 0; /* All off! */ 440 uart->ustcnt = 0; /* All off! */
422 if (!(info->flags & S_INITIALIZED)) 441 if (!(info->tport.flags & ASYNC_INITIALIZED))
423 return; 442 return;
424 443
425 local_irq_save(flags); 444 local_irq_save(flags);
@@ -429,10 +448,10 @@ static void shutdown(struct m68k_serial * info)
429 info->xmit_buf = 0; 448 info->xmit_buf = 0;
430 } 449 }
431 450
432 if (info->tty) 451 if (tty)
433 set_bit(TTY_IO_ERROR, &info->tty->flags); 452 set_bit(TTY_IO_ERROR, &tty->flags);
434 453
435 info->flags &= ~S_INITIALIZED; 454 info->tport.flags &= ~ASYNC_INITIALIZED;
436 local_irq_restore(flags); 455 local_irq_restore(flags);
437} 456}
438 457
@@ -488,7 +507,7 @@ struct {
488 * This routine is called to set the UART divisor registers to match 507 * This routine is called to set the UART divisor registers to match
489 * the specified baud rate for a serial port. 508 * the specified baud rate for a serial port.
490 */ 509 */
491static void change_speed(struct m68k_serial *info) 510static void change_speed(struct m68k_serial *info, struct tty_struct *tty)
492{ 511{
493 m68328_uart *uart = &uart_addr[info->line]; 512 m68328_uart *uart = &uart_addr[info->line];
494 unsigned short port; 513 unsigned short port;
@@ -496,9 +515,7 @@ static void change_speed(struct m68k_serial *info)
496 unsigned cflag; 515 unsigned cflag;
497 int i; 516 int i;
498 517
499 if (!info->tty || !info->tty->termios) 518 cflag = tty->termios->c_cflag;
500 return;
501 cflag = info->tty->termios->c_cflag;
502 if (!(port = info->port)) 519 if (!(port = info->port))
503 return; 520 return;
504 521
@@ -510,7 +527,6 @@ static void change_speed(struct m68k_serial *info)
510 i = (i & ~CBAUDEX) + B38400; 527 i = (i & ~CBAUDEX) + B38400;
511 } 528 }
512 529
513 info->baud = baud_table[i];
514 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | 530 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
515 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); 531 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
516 532
@@ -807,10 +823,10 @@ static int get_serial_info(struct m68k_serial * info,
807 tmp.line = info->line; 823 tmp.line = info->line;
808 tmp.port = info->port; 824 tmp.port = info->port;
809 tmp.irq = info->irq; 825 tmp.irq = info->irq;
810 tmp.flags = info->flags; 826 tmp.flags = info->tport.flags;
811 tmp.baud_base = info->baud_base; 827 tmp.baud_base = info->baud_base;
812 tmp.close_delay = info->close_delay; 828 tmp.close_delay = info->tport.close_delay;
813 tmp.closing_wait = info->closing_wait; 829 tmp.closing_wait = info->tport.closing_wait;
814 tmp.custom_divisor = info->custom_divisor; 830 tmp.custom_divisor = info->custom_divisor;
815 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 831 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
816 return -EFAULT; 832 return -EFAULT;
@@ -818,9 +834,10 @@ static int get_serial_info(struct m68k_serial * info,
818 return 0; 834 return 0;
819} 835}
820 836
821static int set_serial_info(struct m68k_serial * info, 837static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty,
822 struct serial_struct * new_info) 838 struct serial_struct * new_info)
823{ 839{
840 struct tty_port *port = &info->tport;
824 struct serial_struct new_serial; 841 struct serial_struct new_serial;
825 struct m68k_serial old_info; 842 struct m68k_serial old_info;
826 int retval = 0; 843 int retval = 0;
@@ -834,17 +851,17 @@ static int set_serial_info(struct m68k_serial * info,
834 if (!capable(CAP_SYS_ADMIN)) { 851 if (!capable(CAP_SYS_ADMIN)) {
835 if ((new_serial.baud_base != info->baud_base) || 852 if ((new_serial.baud_base != info->baud_base) ||
836 (new_serial.type != info->type) || 853 (new_serial.type != info->type) ||
837 (new_serial.close_delay != info->close_delay) || 854 (new_serial.close_delay != port->close_delay) ||
838 ((new_serial.flags & ~S_USR_MASK) != 855 ((new_serial.flags & ~ASYNC_USR_MASK) !=
839 (info->flags & ~S_USR_MASK))) 856 (port->flags & ~ASYNC_USR_MASK)))
840 return -EPERM; 857 return -EPERM;
841 info->flags = ((info->flags & ~S_USR_MASK) | 858 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
842 (new_serial.flags & S_USR_MASK)); 859 (new_serial.flags & ASYNC_USR_MASK));
843 info->custom_divisor = new_serial.custom_divisor; 860 info->custom_divisor = new_serial.custom_divisor;
844 goto check_and_exit; 861 goto check_and_exit;
845 } 862 }
846 863
847 if (info->count > 1) 864 if (port->count > 1)
848 return -EBUSY; 865 return -EBUSY;
849 866
850 /* 867 /*
@@ -853,14 +870,14 @@ static int set_serial_info(struct m68k_serial * info,
853 */ 870 */
854 871
855 info->baud_base = new_serial.baud_base; 872 info->baud_base = new_serial.baud_base;
856 info->flags = ((info->flags & ~S_FLAGS) | 873 port->flags = ((port->flags & ~ASYNC_FLAGS) |
857 (new_serial.flags & S_FLAGS)); 874 (new_serial.flags & ASYNC_FLAGS));
858 info->type = new_serial.type; 875 info->type = new_serial.type;
859 info->close_delay = new_serial.close_delay; 876 port->close_delay = new_serial.close_delay;
860 info->closing_wait = new_serial.closing_wait; 877 port->closing_wait = new_serial.closing_wait;
861 878
862check_and_exit: 879check_and_exit:
863 retval = startup(info); 880 retval = startup(info, tty);
864 return retval; 881 return retval;
865} 882}
866 883
@@ -946,7 +963,7 @@ static int rs_ioctl(struct tty_struct *tty,
946 return get_serial_info(info, 963 return get_serial_info(info,
947 (struct serial_struct *) arg); 964 (struct serial_struct *) arg);
948 case TIOCSSERIAL: 965 case TIOCSSERIAL:
949 return set_serial_info(info, 966 return set_serial_info(info, tty,
950 (struct serial_struct *) arg); 967 (struct serial_struct *) arg);
951 case TIOCSERGETLSR: /* Get line status register */ 968 case TIOCSERGETLSR: /* Get line status register */
952 return get_lsr_info(info, (unsigned int *) arg); 969 return get_lsr_info(info, (unsigned int *) arg);
@@ -965,7 +982,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
965{ 982{
966 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 983 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
967 984
968 change_speed(info); 985 change_speed(info, tty);
969 986
970 if ((old_termios->c_cflag & CRTSCTS) && 987 if ((old_termios->c_cflag & CRTSCTS) &&
971 !(tty->termios->c_cflag & CRTSCTS)) { 988 !(tty->termios->c_cflag & CRTSCTS)) {
@@ -988,6 +1005,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
988static void rs_close(struct tty_struct *tty, struct file * filp) 1005static void rs_close(struct tty_struct *tty, struct file * filp)
989{ 1006{
990 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; 1007 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
1008 struct tty_port *port = &info->tport;
991 m68328_uart *uart = &uart_addr[info->line]; 1009 m68328_uart *uart = &uart_addr[info->line];
992 unsigned long flags; 1010 unsigned long flags;
993 1011
@@ -1001,7 +1019,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1001 return; 1019 return;
1002 } 1020 }
1003 1021
1004 if ((tty->count == 1) && (info->count != 1)) { 1022 if ((tty->count == 1) && (port->count != 1)) {
1005 /* 1023 /*
1006 * Uh, oh. tty->count is 1, which means that the tty 1024 * Uh, oh. tty->count is 1, which means that the tty
1007 * structure will be freed. Info->count should always 1025 * structure will be freed. Info->count should always
@@ -1010,26 +1028,26 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1010 * serial port won't be shutdown. 1028 * serial port won't be shutdown.
1011 */ 1029 */
1012 printk("rs_close: bad serial port count; tty->count is 1, " 1030 printk("rs_close: bad serial port count; tty->count is 1, "
1013 "info->count is %d\n", info->count); 1031 "port->count is %d\n", port->count);
1014 info->count = 1; 1032 port->count = 1;
1015 } 1033 }
1016 if (--info->count < 0) { 1034 if (--port->count < 0) {
1017 printk("rs_close: bad serial port count for ttyS%d: %d\n", 1035 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1018 info->line, info->count); 1036 info->line, port->count);
1019 info->count = 0; 1037 port->count = 0;
1020 } 1038 }
1021 if (info->count) { 1039 if (port->count) {
1022 local_irq_restore(flags); 1040 local_irq_restore(flags);
1023 return; 1041 return;
1024 } 1042 }
1025 info->flags |= S_CLOSING; 1043 port->flags |= ASYNC_CLOSING;
1026 /* 1044 /*
1027 * Now we wait for the transmit buffer to clear; and we notify 1045 * Now we wait for the transmit buffer to clear; and we notify
1028 * the line discipline to only process XON/XOFF characters. 1046 * the line discipline to only process XON/XOFF characters.
1029 */ 1047 */
1030 tty->closing = 1; 1048 tty->closing = 1;
1031 if (info->closing_wait != S_CLOSING_WAIT_NONE) 1049 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1032 tty_wait_until_sent(tty, info->closing_wait); 1050 tty_wait_until_sent(tty, port->closing_wait);
1033 /* 1051 /*
1034 * At this point we stop accepting input. To do this, we 1052 * At this point we stop accepting input. To do this, we
1035 * disable the receive line status interrupts, and tell the 1053 * disable the receive line status interrupts, and tell the
@@ -1040,13 +1058,12 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1040 uart->ustcnt &= ~USTCNT_RXEN; 1058 uart->ustcnt &= ~USTCNT_RXEN;
1041 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); 1059 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
1042 1060
1043 shutdown(info); 1061 shutdown(info, tty);
1044 rs_flush_buffer(tty); 1062 rs_flush_buffer(tty);
1045 1063
1046 tty_ldisc_flush(tty); 1064 tty_ldisc_flush(tty);
1047 tty->closing = 0; 1065 tty->closing = 0;
1048 info->event = 0; 1066 tty_port_tty_set(&info->tport, NULL);
1049 info->tty = NULL;
1050#warning "This is not and has never been valid so fix it" 1067#warning "This is not and has never been valid so fix it"
1051#if 0 1068#if 0
1052 if (tty->ldisc.num != ldiscs[N_TTY].num) { 1069 if (tty->ldisc.num != ldiscs[N_TTY].num) {
@@ -1058,14 +1075,13 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1058 (tty->ldisc.open)(tty); 1075 (tty->ldisc.open)(tty);
1059 } 1076 }
1060#endif 1077#endif
1061 if (info->blocked_open) { 1078 if (port->blocked_open) {
1062 if (info->close_delay) { 1079 if (port->close_delay)
1063 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1080 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1064 } 1081 wake_up_interruptible(&port->open_wait);
1065 wake_up_interruptible(&info->open_wait);
1066 } 1082 }
1067 info->flags &= ~(S_NORMAL_ACTIVE|S_CLOSING); 1083 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1068 wake_up_interruptible(&info->close_wait); 1084 wake_up_interruptible(&port->close_wait);
1069 local_irq_restore(flags); 1085 local_irq_restore(flags);
1070} 1086}
1071 1087
@@ -1080,107 +1096,14 @@ void rs_hangup(struct tty_struct *tty)
1080 return; 1096 return;
1081 1097
1082 rs_flush_buffer(tty); 1098 rs_flush_buffer(tty);
1083 shutdown(info); 1099 shutdown(info, tty);
1084 info->event = 0; 1100 info->tport.count = 0;
1085 info->count = 0; 1101 info->tport.flags &= ~ASYNC_NORMAL_ACTIVE;
1086 info->flags &= ~S_NORMAL_ACTIVE; 1102 tty_port_tty_set(&info->tport, NULL);
1087 info->tty = NULL; 1103 wake_up_interruptible(&info->tport.open_wait);
1088 wake_up_interruptible(&info->open_wait);
1089} 1104}
1090 1105
1091/* 1106/*
1092 * ------------------------------------------------------------
1093 * rs_open() and friends
1094 * ------------------------------------------------------------
1095 */
1096static int block_til_ready(struct tty_struct *tty, struct file * filp,
1097 struct m68k_serial *info)
1098{
1099 DECLARE_WAITQUEUE(wait, current);
1100 int retval;
1101 int do_clocal = 0;
1102
1103 /*
1104 * If the device is in the middle of being closed, then block
1105 * until it's done, and then try again.
1106 */
1107 if (info->flags & S_CLOSING) {
1108 interruptible_sleep_on(&info->close_wait);
1109#ifdef SERIAL_DO_RESTART
1110 if (info->flags & S_HUP_NOTIFY)
1111 return -EAGAIN;
1112 else
1113 return -ERESTARTSYS;
1114#else
1115 return -EAGAIN;
1116#endif
1117 }
1118
1119 /*
1120 * If non-blocking mode is set, or the port is not enabled,
1121 * then make the check up front and then exit.
1122 */
1123 if ((filp->f_flags & O_NONBLOCK) ||
1124 (tty->flags & (1 << TTY_IO_ERROR))) {
1125 info->flags |= S_NORMAL_ACTIVE;
1126 return 0;
1127 }
1128
1129 if (tty->termios->c_cflag & CLOCAL)
1130 do_clocal = 1;
1131
1132 /*
1133 * Block waiting for the carrier detect and the line to become
1134 * free (i.e., not in use by the callout). While we are in
1135 * this loop, info->count is dropped by one, so that
1136 * rs_close() knows when to free things. We restore it upon
1137 * exit, either normal or abnormal.
1138 */
1139 retval = 0;
1140 add_wait_queue(&info->open_wait, &wait);
1141
1142 info->count--;
1143 info->blocked_open++;
1144 while (1) {
1145 local_irq_disable();
1146 m68k_rtsdtr(info, 1);
1147 local_irq_enable();
1148 current->state = TASK_INTERRUPTIBLE;
1149 if (tty_hung_up_p(filp) ||
1150 !(info->flags & S_INITIALIZED)) {
1151#ifdef SERIAL_DO_RESTART
1152 if (info->flags & S_HUP_NOTIFY)
1153 retval = -EAGAIN;
1154 else
1155 retval = -ERESTARTSYS;
1156#else
1157 retval = -EAGAIN;
1158#endif
1159 break;
1160 }
1161 if (!(info->flags & S_CLOSING) && do_clocal)
1162 break;
1163 if (signal_pending(current)) {
1164 retval = -ERESTARTSYS;
1165 break;
1166 }
1167 tty_unlock();
1168 schedule();
1169 tty_lock();
1170 }
1171 current->state = TASK_RUNNING;
1172 remove_wait_queue(&info->open_wait, &wait);
1173 if (!tty_hung_up_p(filp))
1174 info->count++;
1175 info->blocked_open--;
1176
1177 if (retval)
1178 return retval;
1179 info->flags |= S_NORMAL_ACTIVE;
1180 return 0;
1181}
1182
1183/*
1184 * This routine is called whenever a serial port is opened. It 1107 * This routine is called whenever a serial port is opened. It
1185 * enables interrupts for a serial port, linking in its S structure into 1108 * enables interrupts for a serial port, linking in its S structure into
1186 * the IRQ chain. It also performs the serial-specific 1109 * the IRQ chain. It also performs the serial-specific
@@ -1196,18 +1119,18 @@ int rs_open(struct tty_struct *tty, struct file * filp)
1196 if (serial_paranoia_check(info, tty->name, "rs_open")) 1119 if (serial_paranoia_check(info, tty->name, "rs_open"))
1197 return -ENODEV; 1120 return -ENODEV;
1198 1121
1199 info->count++; 1122 info->tport.count++;
1200 tty->driver_data = info; 1123 tty->driver_data = info;
1201 info->tty = tty; 1124 tty_port_tty_set(&info->tport, tty);
1202 1125
1203 /* 1126 /*
1204 * Start up serial port 1127 * Start up serial port
1205 */ 1128 */
1206 retval = startup(info); 1129 retval = startup(info, tty);
1207 if (retval) 1130 if (retval)
1208 return retval; 1131 return retval;
1209 1132
1210 return block_til_ready(tty, filp, info); 1133 return tty_port_block_til_ready(&info->tport, tty, filp);
1211} 1134}
1212 1135
1213/* Finally, routines used to initialize the serial driver. */ 1136/* Finally, routines used to initialize the serial driver. */
@@ -1235,11 +1158,15 @@ static const struct tty_operations rs_ops = {
1235 .set_ldisc = rs_set_ldisc, 1158 .set_ldisc = rs_set_ldisc,
1236}; 1159};
1237 1160
1161static const struct tty_port_operations rs_port_ops = {
1162};
1163
1238/* rs_init inits the driver */ 1164/* rs_init inits the driver */
1239static int __init 1165static int __init
1240rs68328_init(void) 1166rs68328_init(void)
1241{ 1167{
1242 int flags, i; 1168 unsigned long flags;
1169 int i;
1243 struct m68k_serial *info; 1170 struct m68k_serial *info;
1244 1171
1245 serial_driver = alloc_tty_driver(NR_PORTS); 1172 serial_driver = alloc_tty_driver(NR_PORTS);
@@ -1273,19 +1200,13 @@ rs68328_init(void)
1273 for(i=0;i<NR_PORTS;i++) { 1200 for(i=0;i<NR_PORTS;i++) {
1274 1201
1275 info = &m68k_soft[i]; 1202 info = &m68k_soft[i];
1203 tty_port_init(&info->tport);
1204 info->tport.ops = &rs_port_ops;
1276 info->magic = SERIAL_MAGIC; 1205 info->magic = SERIAL_MAGIC;
1277 info->port = (int) &uart_addr[i]; 1206 info->port = (int) &uart_addr[i];
1278 info->tty = NULL;
1279 info->irq = uart_irqs[i]; 1207 info->irq = uart_irqs[i];
1280 info->custom_divisor = 16; 1208 info->custom_divisor = 16;
1281 info->close_delay = 50;
1282 info->closing_wait = 3000;
1283 info->x_char = 0; 1209 info->x_char = 0;
1284 info->event = 0;
1285 info->count = 0;
1286 info->blocked_open = 0;
1287 init_waitqueue_head(&info->open_wait);
1288 init_waitqueue_head(&info->close_wait);
1289 info->line = i; 1210 info->line = i;
1290 info->is_cons = 1; /* Means shortcuts work */ 1211 info->is_cons = 1; /* Means shortcuts work */
1291 1212