First Support on Ginger and OMAP TI
[linux-ginger.git] / drivers / char / generic_serial.c
blobd400cbd280f2fbb858102f0defb111a583979f3a
1 /*
2 * generic_serial.c
4 * Copyright (C) 1998/1999 R.E.Wolff@BitWizard.nl
6 * written for the SX serial driver.
7 * Contains the code that should be shared over all the serial drivers.
9 * Credit for the idea to do it this way might go to Alan Cox.
12 * Version 0.1 -- December, 1998. Initial version.
13 * Version 0.2 -- March, 1999. Some more routines. Bugfixes. Etc.
14 * Version 0.5 -- August, 1999. Some more fixes. Reformat for Linus.
16 * BitWizard is actively maintaining this file. We sometimes find
17 * that someone submitted changes to this file. We really appreciate
18 * your help, but please submit changes through us. We're doing our
19 * best to be responsive. -- REW
20 * */
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/tty.h>
25 #include <linux/sched.h>
26 #include <linux/serial.h>
27 #include <linux/mm.h>
28 #include <linux/generic_serial.h>
29 #include <linux/interrupt.h>
30 #include <linux/tty_flip.h>
31 #include <linux/delay.h>
32 #include <asm/uaccess.h>
34 #define DEBUG
36 static int gs_debug;
38 #ifdef DEBUG
39 #define gs_dprintk(f, str...) if (gs_debug & f) printk (str)
40 #else
41 #define gs_dprintk(f, str...) /* nothing */
42 #endif
44 #define func_enter() gs_dprintk (GS_DEBUG_FLOW, "gs: enter %s\n", __func__)
45 #define func_exit() gs_dprintk (GS_DEBUG_FLOW, "gs: exit %s\n", __func__)
47 #define RS_EVENT_WRITE_WAKEUP 1
49 module_param(gs_debug, int, 0644);
52 int gs_put_char(struct tty_struct * tty, unsigned char ch)
54 struct gs_port *port;
56 func_enter ();
58 port = tty->driver_data;
60 if (!port) return 0;
62 if (! (port->port.flags & ASYNC_INITIALIZED)) return 0;
64 /* Take a lock on the serial tranmit buffer! */
65 mutex_lock(& port->port_write_mutex);
67 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
68 /* Sorry, buffer is full, drop character. Update statistics???? -- REW */
69 mutex_unlock(&port->port_write_mutex);
70 return 0;
73 port->xmit_buf[port->xmit_head++] = ch;
74 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
75 port->xmit_cnt++; /* Characters in buffer */
77 mutex_unlock(&port->port_write_mutex);
78 func_exit ();
79 return 1;
84 > Problems to take into account are:
85 > -1- Interrupts that empty part of the buffer.
86 > -2- page faults on the access to userspace.
87 > -3- Other processes that are also trying to do a "write".
90 int gs_write(struct tty_struct * tty,
91 const unsigned char *buf, int count)
93 struct gs_port *port;
94 int c, total = 0;
95 int t;
97 func_enter ();
99 port = tty->driver_data;
101 if (!port) return 0;
103 if (! (port->port.flags & ASYNC_INITIALIZED))
104 return 0;
106 /* get exclusive "write" access to this port (problem 3) */
107 /* This is not a spinlock because we can have a disk access (page
108 fault) in copy_from_user */
109 mutex_lock(& port->port_write_mutex);
111 while (1) {
113 c = count;
115 /* This is safe because we "OWN" the "head". Noone else can
116 change the "head": we own the port_write_mutex. */
117 /* Don't overrun the end of the buffer */
118 t = SERIAL_XMIT_SIZE - port->xmit_head;
119 if (t < c) c = t;
121 /* This is safe because the xmit_cnt can only decrease. This
122 would increase "t", so we might copy too little chars. */
123 /* Don't copy past the "head" of the buffer */
124 t = SERIAL_XMIT_SIZE - 1 - port->xmit_cnt;
125 if (t < c) c = t;
127 /* Can't copy more? break out! */
128 if (c <= 0) break;
130 memcpy (port->xmit_buf + port->xmit_head, buf, c);
132 port -> xmit_cnt += c;
133 port -> xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE -1);
134 buf += c;
135 count -= c;
136 total += c;
138 mutex_unlock(& port->port_write_mutex);
140 gs_dprintk (GS_DEBUG_WRITE, "write: interrupts are %s\n",
141 (port->port.flags & GS_TX_INTEN)?"enabled": "disabled");
143 if (port->xmit_cnt &&
144 !tty->stopped &&
145 !tty->hw_stopped &&
146 !(port->port.flags & GS_TX_INTEN)) {
147 port->port.flags |= GS_TX_INTEN;
148 port->rd->enable_tx_interrupts (port);
150 func_exit ();
151 return total;
156 int gs_write_room(struct tty_struct * tty)
158 struct gs_port *port = tty->driver_data;
159 int ret;
161 func_enter ();
162 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
163 if (ret < 0)
164 ret = 0;
165 func_exit ();
166 return ret;
170 int gs_chars_in_buffer(struct tty_struct *tty)
172 struct gs_port *port = tty->driver_data;
173 func_enter ();
175 func_exit ();
176 return port->xmit_cnt;
180 static int gs_real_chars_in_buffer(struct tty_struct *tty)
182 struct gs_port *port;
183 func_enter ();
185 port = tty->driver_data;
187 if (!port->rd) return 0;
188 if (!port->rd->chars_in_buffer) return 0;
190 func_exit ();
191 return port->xmit_cnt + port->rd->chars_in_buffer (port);
195 static int gs_wait_tx_flushed (void * ptr, unsigned long timeout)
197 struct gs_port *port = ptr;
198 unsigned long end_jiffies;
199 int jiffies_to_transmit, charsleft = 0, rv = 0;
200 int rcib;
202 func_enter();
204 gs_dprintk (GS_DEBUG_FLUSH, "port=%p.\n", port);
205 if (port) {
206 gs_dprintk (GS_DEBUG_FLUSH, "xmit_cnt=%x, xmit_buf=%p, tty=%p.\n",
207 port->xmit_cnt, port->xmit_buf, port->port.tty);
210 if (!port || port->xmit_cnt < 0 || !port->xmit_buf) {
211 gs_dprintk (GS_DEBUG_FLUSH, "ERROR: !port, !port->xmit_buf or prot->xmit_cnt < 0.\n");
212 func_exit();
213 return -EINVAL; /* This is an error which we don't know how to handle. */
216 rcib = gs_real_chars_in_buffer(port->port.tty);
218 if(rcib <= 0) {
219 gs_dprintk (GS_DEBUG_FLUSH, "nothing to wait for.\n");
220 func_exit();
221 return rv;
223 /* stop trying: now + twice the time it would normally take + seconds */
224 if (timeout == 0) timeout = MAX_SCHEDULE_TIMEOUT;
225 end_jiffies = jiffies;
226 if (timeout != MAX_SCHEDULE_TIMEOUT)
227 end_jiffies += port->baud?(2 * rcib * 10 * HZ / port->baud):0;
228 end_jiffies += timeout;
230 gs_dprintk (GS_DEBUG_FLUSH, "now=%lx, end=%lx (%ld).\n",
231 jiffies, end_jiffies, end_jiffies-jiffies);
233 /* the expression is actually jiffies < end_jiffies, but that won't
234 work around the wraparound. Tricky eh? */
235 while ((charsleft = gs_real_chars_in_buffer (port->port.tty)) &&
236 time_after (end_jiffies, jiffies)) {
237 /* Units check:
238 chars * (bits/char) * (jiffies /sec) / (bits/sec) = jiffies!
239 check! */
241 charsleft += 16; /* Allow 16 chars more to be transmitted ... */
242 jiffies_to_transmit = port->baud?(1 + charsleft * 10 * HZ / port->baud):0;
243 /* ^^^ Round up.... */
244 if (jiffies_to_transmit <= 0) jiffies_to_transmit = 1;
246 gs_dprintk (GS_DEBUG_FLUSH, "Expect to finish in %d jiffies "
247 "(%d chars).\n", jiffies_to_transmit, charsleft);
249 msleep_interruptible(jiffies_to_msecs(jiffies_to_transmit));
250 if (signal_pending (current)) {
251 gs_dprintk (GS_DEBUG_FLUSH, "Signal pending. Bombing out: ");
252 rv = -EINTR;
253 break;
257 gs_dprintk (GS_DEBUG_FLUSH, "charsleft = %d.\n", charsleft);
258 set_current_state (TASK_RUNNING);
260 func_exit();
261 return rv;
266 void gs_flush_buffer(struct tty_struct *tty)
268 struct gs_port *port;
269 unsigned long flags;
271 func_enter ();
273 port = tty->driver_data;
275 if (!port) return;
277 /* XXX Would the write semaphore do? */
278 spin_lock_irqsave (&port->driver_lock, flags);
279 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
280 spin_unlock_irqrestore (&port->driver_lock, flags);
282 tty_wakeup(tty);
283 func_exit ();
287 void gs_flush_chars(struct tty_struct * tty)
289 struct gs_port *port;
291 func_enter ();
293 port = tty->driver_data;
295 if (!port) return;
297 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
298 !port->xmit_buf) {
299 func_exit ();
300 return;
303 /* Beats me -- REW */
304 port->port.flags |= GS_TX_INTEN;
305 port->rd->enable_tx_interrupts (port);
306 func_exit ();
310 void gs_stop(struct tty_struct * tty)
312 struct gs_port *port;
314 func_enter ();
316 port = tty->driver_data;
318 if (!port) return;
320 if (port->xmit_cnt &&
321 port->xmit_buf &&
322 (port->port.flags & GS_TX_INTEN) ) {
323 port->port.flags &= ~GS_TX_INTEN;
324 port->rd->disable_tx_interrupts (port);
326 func_exit ();
330 void gs_start(struct tty_struct * tty)
332 struct gs_port *port;
334 port = tty->driver_data;
336 if (!port) return;
338 if (port->xmit_cnt &&
339 port->xmit_buf &&
340 !(port->port.flags & GS_TX_INTEN) ) {
341 port->port.flags |= GS_TX_INTEN;
342 port->rd->enable_tx_interrupts (port);
344 func_exit ();
348 static void gs_shutdown_port (struct gs_port *port)
350 unsigned long flags;
352 func_enter();
354 if (!port) return;
356 if (!(port->port.flags & ASYNC_INITIALIZED))
357 return;
359 spin_lock_irqsave(&port->driver_lock, flags);
361 if (port->xmit_buf) {
362 free_page((unsigned long) port->xmit_buf);
363 port->xmit_buf = NULL;
366 if (port->port.tty)
367 set_bit(TTY_IO_ERROR, &port->port.tty->flags);
369 port->rd->shutdown_port (port);
371 port->port.flags &= ~ASYNC_INITIALIZED;
372 spin_unlock_irqrestore(&port->driver_lock, flags);
374 func_exit();
378 void gs_hangup(struct tty_struct *tty)
380 struct gs_port *port;
381 unsigned long flags;
383 func_enter ();
385 port = tty->driver_data;
386 tty = port->port.tty;
387 if (!tty)
388 return;
390 gs_shutdown_port (port);
391 spin_lock_irqsave(&port->port.lock, flags);
392 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|GS_ACTIVE);
393 port->port.tty = NULL;
394 port->port.count = 0;
395 spin_unlock_irqrestore(&port->port.lock, flags);
397 wake_up_interruptible(&port->port.open_wait);
398 func_exit ();
402 int gs_block_til_ready(void *port_, struct file * filp)
404 struct gs_port *gp = port_;
405 struct tty_port *port = &gp->port;
406 DECLARE_WAITQUEUE(wait, current);
407 int retval;
408 int do_clocal = 0;
409 int CD;
410 struct tty_struct *tty;
411 unsigned long flags;
413 func_enter ();
415 if (!port) return 0;
417 tty = port->tty;
419 gs_dprintk (GS_DEBUG_BTR, "Entering gs_block_till_ready.\n");
421 * If the device is in the middle of being closed, then block
422 * until it's done, and then try again.
424 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
425 interruptible_sleep_on(&port->close_wait);
426 if (port->flags & ASYNC_HUP_NOTIFY)
427 return -EAGAIN;
428 else
429 return -ERESTARTSYS;
432 gs_dprintk (GS_DEBUG_BTR, "after hung up\n");
435 * If non-blocking mode is set, or the port is not enabled,
436 * then make the check up front and then exit.
438 if ((filp->f_flags & O_NONBLOCK) ||
439 (tty->flags & (1 << TTY_IO_ERROR))) {
440 port->flags |= ASYNC_NORMAL_ACTIVE;
441 return 0;
444 gs_dprintk (GS_DEBUG_BTR, "after nonblock\n");
446 if (C_CLOCAL(tty))
447 do_clocal = 1;
450 * Block waiting for the carrier detect and the line to become
451 * free (i.e., not in use by the callout). While we are in
452 * this loop, port->count is dropped by one, so that
453 * rs_close() knows when to free things. We restore it upon
454 * exit, either normal or abnormal.
456 retval = 0;
458 add_wait_queue(&port->open_wait, &wait);
460 gs_dprintk (GS_DEBUG_BTR, "after add waitq.\n");
461 spin_lock_irqsave(&port->lock, flags);
462 if (!tty_hung_up_p(filp)) {
463 port->count--;
465 port->blocked_open++;
466 spin_unlock_irqrestore(&port->lock, flags);
467 while (1) {
468 CD = tty_port_carrier_raised(port);
469 gs_dprintk (GS_DEBUG_BTR, "CD is now %d.\n", CD);
470 set_current_state (TASK_INTERRUPTIBLE);
471 if (tty_hung_up_p(filp) ||
472 !(port->flags & ASYNC_INITIALIZED)) {
473 if (port->flags & ASYNC_HUP_NOTIFY)
474 retval = -EAGAIN;
475 else
476 retval = -ERESTARTSYS;
477 break;
479 if (!(port->flags & ASYNC_CLOSING) &&
480 (do_clocal || CD))
481 break;
482 gs_dprintk (GS_DEBUG_BTR, "signal_pending is now: %d (%lx)\n",
483 (int)signal_pending (current), *(long*)(&current->blocked));
484 if (signal_pending(current)) {
485 retval = -ERESTARTSYS;
486 break;
488 schedule();
490 gs_dprintk (GS_DEBUG_BTR, "Got out of the loop. (%d)\n",
491 port->blocked_open);
492 set_current_state (TASK_RUNNING);
493 remove_wait_queue(&port->open_wait, &wait);
495 spin_lock_irqsave(&port->lock, flags);
496 if (!tty_hung_up_p(filp)) {
497 port->count++;
499 port->blocked_open--;
500 if (retval == 0)
501 port->flags |= ASYNC_NORMAL_ACTIVE;
502 spin_unlock_irqrestore(&port->lock, flags);
503 func_exit ();
504 return retval;
508 void gs_close(struct tty_struct * tty, struct file * filp)
510 unsigned long flags;
511 struct gs_port *port;
513 func_enter ();
515 port = tty->driver_data;
517 if (!port) return;
519 if (!port->port.tty) {
520 /* This seems to happen when this is called from vhangup. */
521 gs_dprintk (GS_DEBUG_CLOSE, "gs: Odd: port->port.tty is NULL\n");
522 port->port.tty = tty;
525 spin_lock_irqsave(&port->port.lock, flags);
527 if (tty_hung_up_p(filp)) {
528 spin_unlock_irqrestore(&port->port.lock, flags);
529 if (port->rd->hungup)
530 port->rd->hungup (port);
531 func_exit ();
532 return;
535 if ((tty->count == 1) && (port->port.count != 1)) {
536 printk(KERN_ERR "gs: gs_close port %p: bad port count;"
537 " tty->count is 1, port count is %d\n", port, port->port.count);
538 port->port.count = 1;
540 if (--port->port.count < 0) {
541 printk(KERN_ERR "gs: gs_close port %p: bad port count: %d\n", port, port->port.count);
542 port->port.count = 0;
545 if (port->port.count) {
546 gs_dprintk(GS_DEBUG_CLOSE, "gs_close port %p: count: %d\n", port, port->port.count);
547 spin_unlock_irqrestore(&port->port.lock, flags);
548 func_exit ();
549 return;
551 port->port.flags |= ASYNC_CLOSING;
554 * Now we wait for the transmit buffer to clear; and we notify
555 * the line discipline to only process XON/XOFF characters.
557 tty->closing = 1;
558 /* if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
559 tty_wait_until_sent(tty, port->closing_wait); */
562 * At this point we stop accepting input. To do this, we
563 * disable the receive line status interrupts, and tell the
564 * interrupt driver to stop checking the data ready bit in the
565 * line status register.
568 spin_lock_irqsave(&port->driver_lock, flags);
569 port->rd->disable_rx_interrupts (port);
570 spin_unlock_irqrestore(&port->driver_lock, flags);
571 spin_unlock_irqrestore(&port->port.lock, flags);
573 /* close has no way of returning "EINTR", so discard return value */
574 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
575 gs_wait_tx_flushed (port, port->closing_wait);
577 port->port.flags &= ~GS_ACTIVE;
579 gs_flush_buffer(tty);
581 tty_ldisc_flush(tty);
582 tty->closing = 0;
584 spin_lock_irqsave(&port->driver_lock, flags);
585 port->event = 0;
586 port->rd->close (port);
587 port->rd->shutdown_port (port);
588 spin_unlock_irqrestore(&port->driver_lock, flags);
590 spin_lock_irqsave(&port->port.lock, flags);
591 port->port.tty = NULL;
593 if (port->port.blocked_open) {
594 if (port->close_delay) {
595 spin_unlock_irqrestore(&port->port.lock, flags);
596 msleep_interruptible(jiffies_to_msecs(port->close_delay));
597 spin_lock_irqsave(&port->port.lock, flags);
599 wake_up_interruptible(&port->port.open_wait);
601 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING | ASYNC_INITIALIZED);
602 spin_unlock_irqrestore(&port->port.lock, flags);
603 wake_up_interruptible(&port->port.close_wait);
605 func_exit ();
609 void gs_set_termios (struct tty_struct * tty,
610 struct ktermios * old_termios)
612 struct gs_port *port;
613 int baudrate, tmp, rv;
614 struct ktermios *tiosp;
616 func_enter();
618 port = tty->driver_data;
620 if (!port) return;
621 if (!port->port.tty) {
622 /* This seems to happen when this is called after gs_close. */
623 gs_dprintk (GS_DEBUG_TERMIOS, "gs: Odd: port->port.tty is NULL\n");
624 port->port.tty = tty;
628 tiosp = tty->termios;
630 if (gs_debug & GS_DEBUG_TERMIOS) {
631 gs_dprintk (GS_DEBUG_TERMIOS, "termios structure (%p):\n", tiosp);
634 if(old_termios && (gs_debug & GS_DEBUG_TERMIOS)) {
635 if(tiosp->c_iflag != old_termios->c_iflag) printk("c_iflag changed\n");
636 if(tiosp->c_oflag != old_termios->c_oflag) printk("c_oflag changed\n");
637 if(tiosp->c_cflag != old_termios->c_cflag) printk("c_cflag changed\n");
638 if(tiosp->c_lflag != old_termios->c_lflag) printk("c_lflag changed\n");
639 if(tiosp->c_line != old_termios->c_line) printk("c_line changed\n");
640 if(!memcmp(tiosp->c_cc, old_termios->c_cc, NCC)) printk("c_cc changed\n");
643 baudrate = tty_get_baud_rate(tty);
645 if ((tiosp->c_cflag & CBAUD) == B38400) {
646 if ( (port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
647 baudrate = 57600;
648 else if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
649 baudrate = 115200;
650 else if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
651 baudrate = 230400;
652 else if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
653 baudrate = 460800;
654 else if ((port->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
655 baudrate = (port->baud_base / port->custom_divisor);
658 /* I recommend using THIS instead of the mess in termios (and
659 duplicating the above code). Next we should create a clean
660 interface towards this variable. If your card supports arbitrary
661 baud rates, (e.g. CD1400 or 16550 based cards) then everything
662 will be very easy..... */
663 port->baud = baudrate;
665 /* Two timer ticks seems enough to wakeup something like SLIP driver */
666 /* Baudrate/10 is cps. Divide by HZ to get chars per tick. */
667 tmp = (baudrate / 10 / HZ) * 2;
669 if (tmp < 0) tmp = 0;
670 if (tmp >= SERIAL_XMIT_SIZE) tmp = SERIAL_XMIT_SIZE-1;
672 port->wakeup_chars = tmp;
674 /* We should really wait for the characters to be all sent before
675 changing the settings. -- CAL */
676 rv = gs_wait_tx_flushed (port, MAX_SCHEDULE_TIMEOUT);
677 if (rv < 0) return /* rv */;
679 rv = port->rd->set_real_termios(port);
680 if (rv < 0) return /* rv */;
682 if ((!old_termios ||
683 (old_termios->c_cflag & CRTSCTS)) &&
684 !( tiosp->c_cflag & CRTSCTS)) {
685 tty->stopped = 0;
686 gs_start(tty);
689 #ifdef tytso_patch_94Nov25_1726
690 /* This "makes sense", Why is it commented out? */
692 if (!(old_termios->c_cflag & CLOCAL) &&
693 (tty->termios->c_cflag & CLOCAL))
694 wake_up_interruptible(&port->gs.open_wait);
695 #endif
697 func_exit();
698 return /* 0 */;
703 /* Must be called with interrupts enabled */
704 int gs_init_port(struct gs_port *port)
706 unsigned long flags;
708 func_enter ();
710 if (port->port.flags & ASYNC_INITIALIZED) {
711 func_exit ();
712 return 0;
714 if (!port->xmit_buf) {
715 /* We may sleep in get_zeroed_page() */
716 unsigned long tmp;
718 tmp = get_zeroed_page(GFP_KERNEL);
719 spin_lock_irqsave (&port->driver_lock, flags);
720 if (port->xmit_buf)
721 free_page (tmp);
722 else
723 port->xmit_buf = (unsigned char *) tmp;
724 spin_unlock_irqrestore(&port->driver_lock, flags);
725 if (!port->xmit_buf) {
726 func_exit ();
727 return -ENOMEM;
731 spin_lock_irqsave (&port->driver_lock, flags);
732 if (port->port.tty)
733 clear_bit(TTY_IO_ERROR, &port->port.tty->flags);
734 mutex_init(&port->port_write_mutex);
735 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
736 spin_unlock_irqrestore(&port->driver_lock, flags);
737 gs_set_termios(port->port.tty, NULL);
738 spin_lock_irqsave (&port->driver_lock, flags);
739 port->port.flags |= ASYNC_INITIALIZED;
740 port->port.flags &= ~GS_TX_INTEN;
742 spin_unlock_irqrestore(&port->driver_lock, flags);
743 func_exit ();
744 return 0;
748 int gs_setserial(struct gs_port *port, struct serial_struct __user *sp)
750 struct serial_struct sio;
752 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
753 return(-EFAULT);
755 if (!capable(CAP_SYS_ADMIN)) {
756 if ((sio.baud_base != port->baud_base) ||
757 (sio.close_delay != port->close_delay) ||
758 ((sio.flags & ~ASYNC_USR_MASK) !=
759 (port->port.flags & ~ASYNC_USR_MASK)))
760 return(-EPERM);
763 port->port.flags = (port->port.flags & ~ASYNC_USR_MASK) |
764 (sio.flags & ASYNC_USR_MASK);
766 port->baud_base = sio.baud_base;
767 port->close_delay = sio.close_delay;
768 port->closing_wait = sio.closing_wait;
769 port->custom_divisor = sio.custom_divisor;
771 gs_set_termios (port->port.tty, NULL);
773 return 0;
777 /*****************************************************************************/
780 * Generate the serial struct info.
783 int gs_getserial(struct gs_port *port, struct serial_struct __user *sp)
785 struct serial_struct sio;
787 memset(&sio, 0, sizeof(struct serial_struct));
788 sio.flags = port->port.flags;
789 sio.baud_base = port->baud_base;
790 sio.close_delay = port->close_delay;
791 sio.closing_wait = port->closing_wait;
792 sio.custom_divisor = port->custom_divisor;
793 sio.hub6 = 0;
795 /* If you want you can override these. */
796 sio.type = PORT_UNKNOWN;
797 sio.xmit_fifo_size = -1;
798 sio.line = -1;
799 sio.port = -1;
800 sio.irq = -1;
802 if (port->rd->getserial)
803 port->rd->getserial (port, &sio);
805 if (copy_to_user(sp, &sio, sizeof(struct serial_struct)))
806 return -EFAULT;
807 return 0;
812 void gs_got_break(struct gs_port *port)
814 func_enter ();
816 tty_insert_flip_char(port->port.tty, 0, TTY_BREAK);
817 tty_schedule_flip(port->port.tty);
818 if (port->port.flags & ASYNC_SAK) {
819 do_SAK (port->port.tty);
822 func_exit ();
826 EXPORT_SYMBOL(gs_put_char);
827 EXPORT_SYMBOL(gs_write);
828 EXPORT_SYMBOL(gs_write_room);
829 EXPORT_SYMBOL(gs_chars_in_buffer);
830 EXPORT_SYMBOL(gs_flush_buffer);
831 EXPORT_SYMBOL(gs_flush_chars);
832 EXPORT_SYMBOL(gs_stop);
833 EXPORT_SYMBOL(gs_start);
834 EXPORT_SYMBOL(gs_hangup);
835 EXPORT_SYMBOL(gs_block_til_ready);
836 EXPORT_SYMBOL(gs_close);
837 EXPORT_SYMBOL(gs_set_termios);
838 EXPORT_SYMBOL(gs_init_port);
839 EXPORT_SYMBOL(gs_setserial);
840 EXPORT_SYMBOL(gs_getserial);
841 EXPORT_SYMBOL(gs_got_break);
843 MODULE_LICENSE("GPL");