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
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/tty.h>
25 #include <linux/serial.h>
27 #include <linux/generic_serial.h>
28 #include <linux/interrupt.h>
29 #include <linux/tty_flip.h>
30 #include <linux/delay.h>
31 #include <asm/semaphore.h>
32 #include <asm/uaccess.h>
39 #define gs_dprintk(f, str...) if (gs_debug & f) printk (str)
41 #define gs_dprintk(f, str...) /* nothing */
44 #define func_enter() gs_dprintk (GS_DEBUG_FLOW, "gs: enter %s\n", __FUNCTION__)
45 #define func_exit() gs_dprintk (GS_DEBUG_FLOW, "gs: exit %s\n", __FUNCTION__)
46 #define NEW_WRITE_LOCKING 1
48 #define DECL /* Nothing */
49 #define LOCKIT mutex_lock(& port->port_write_mutex);
50 #define RELEASEIT mutex_unlock(&port->port_write_mutex);
52 #define DECL unsigned long flags;
53 #define LOCKIT save_flags (flags);cli ()
54 #define RELEASEIT restore_flags (flags)
57 #define RS_EVENT_WRITE_WAKEUP 1
59 module_param(gs_debug
, int, 0644);
62 void gs_put_char(struct tty_struct
* tty
, unsigned char ch
)
71 port
= tty
->driver_data
;
75 if (! (port
->flags
& ASYNC_INITIALIZED
)) return;
77 /* Take a lock on the serial tranmit buffer! */
80 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
81 /* Sorry, buffer is full, drop character. Update statistics???? -- REW */
86 port
->xmit_buf
[port
->xmit_head
++] = ch
;
87 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
88 port
->xmit_cnt
++; /* Characters in buffer */
95 #ifdef NEW_WRITE_LOCKING
98 > Problems to take into account are:
99 > -1- Interrupts that empty part of the buffer.
100 > -2- page faults on the access to userspace.
101 > -3- Other processes that are also trying to do a "write".
104 int gs_write(struct tty_struct
* tty
,
105 const unsigned char *buf
, int count
)
107 struct gs_port
*port
;
115 port
= tty
->driver_data
;
119 if (! (port
->flags
& ASYNC_INITIALIZED
))
122 /* get exclusive "write" access to this port (problem 3) */
123 /* This is not a spinlock because we can have a disk access (page
124 fault) in copy_from_user */
125 mutex_lock(& port
->port_write_mutex
);
131 /* This is safe because we "OWN" the "head". Noone else can
132 change the "head": we own the port_write_mutex. */
133 /* Don't overrun the end of the buffer */
134 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
137 /* This is safe because the xmit_cnt can only decrease. This
138 would increase "t", so we might copy too little chars. */
139 /* Don't copy past the "head" of the buffer */
140 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
143 /* Can't copy more? break out! */
146 memcpy (port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
148 port
-> xmit_cnt
+= c
;
149 port
-> xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
154 mutex_unlock(& port
->port_write_mutex
);
156 gs_dprintk (GS_DEBUG_WRITE
, "write: interrupts are %s\n",
157 (port
->flags
& GS_TX_INTEN
)?"enabled": "disabled");
159 if (port
->xmit_cnt
&&
162 !(port
->flags
& GS_TX_INTEN
)) {
163 port
->flags
|= GS_TX_INTEN
;
164 port
->rd
->enable_tx_interrupts (port
);
171 > Problems to take into account are:
172 > -1- Interrupts that empty part of the buffer.
173 > -2- page faults on the access to userspace.
174 > -3- Other processes that are also trying to do a "write".
177 int gs_write(struct tty_struct
* tty
,
178 const unsigned char *buf
, int count
)
180 struct gs_port
*port
;
187 /* The standard serial driver returns 0 in this case.
188 That sounds to me as "No error, I just didn't get to writing any
189 bytes. Feel free to try again."
190 The "official" way to write n bytes from buf is:
192 for (nwritten = 0;nwritten < n;nwritten += rv) {
193 rv = write (fd, buf+nwritten, n-nwritten);
194 if (rv < 0) break; // Error: bail out. //
197 which will loop endlessly in this case. The manual page for write
198 agrees with me. In practise almost everybody writes
199 "write (fd, buf,n);" but some people might have had to deal with
200 incomplete writes in the past and correctly implemented it by now...
203 if (!tty
) return -EIO
;
205 port
= tty
->driver_data
;
206 if (!port
|| !port
->xmit_buf
)
209 local_save_flags(flags
);
214 /* This is safe because we "OWN" the "head". Noone else can
215 change the "head": we own the port_write_mutex. */
216 /* Don't overrun the end of the buffer */
217 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
220 /* This is safe because the xmit_cnt can only decrease. This
221 would increase "t", so we might copy too little chars. */
222 /* Don't copy past the "head" of the buffer */
223 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
226 /* Can't copy more? break out! */
228 local_restore_flags(flags
);
231 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
232 port
->xmit_head
= ((port
->xmit_head
+ c
) &
233 (SERIAL_XMIT_SIZE
-1));
235 local_restore_flags(flags
);
241 if (port
->xmit_cnt
&&
244 !(port
->flags
& GS_TX_INTEN
)) {
245 port
->flags
|= GS_TX_INTEN
;
246 port
->rd
->enable_tx_interrupts (port
);
256 int gs_write_room(struct tty_struct
* tty
)
258 struct gs_port
*port
= tty
->driver_data
;
262 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
270 int gs_chars_in_buffer(struct tty_struct
*tty
)
272 struct gs_port
*port
= tty
->driver_data
;
276 return port
->xmit_cnt
;
280 static int gs_real_chars_in_buffer(struct tty_struct
*tty
)
282 struct gs_port
*port
;
286 port
= tty
->driver_data
;
288 if (!port
->rd
) return 0;
289 if (!port
->rd
->chars_in_buffer
) return 0;
292 return port
->xmit_cnt
+ port
->rd
->chars_in_buffer (port
);
296 static int gs_wait_tx_flushed (void * ptr
, unsigned long timeout
)
298 struct gs_port
*port
= ptr
;
299 unsigned long end_jiffies
;
300 int jiffies_to_transmit
, charsleft
= 0, rv
= 0;
305 gs_dprintk (GS_DEBUG_FLUSH
, "port=%p.\n", port
);
307 gs_dprintk (GS_DEBUG_FLUSH
, "xmit_cnt=%x, xmit_buf=%p, tty=%p.\n",
308 port
->xmit_cnt
, port
->xmit_buf
, port
->tty
);
311 if (!port
|| port
->xmit_cnt
< 0 || !port
->xmit_buf
) {
312 gs_dprintk (GS_DEBUG_FLUSH
, "ERROR: !port, !port->xmit_buf or prot->xmit_cnt < 0.\n");
314 return -EINVAL
; /* This is an error which we don't know how to handle. */
317 rcib
= gs_real_chars_in_buffer(port
->tty
);
320 gs_dprintk (GS_DEBUG_FLUSH
, "nothing to wait for.\n");
324 /* stop trying: now + twice the time it would normally take + seconds */
325 if (timeout
== 0) timeout
= MAX_SCHEDULE_TIMEOUT
;
326 end_jiffies
= jiffies
;
327 if (timeout
!= MAX_SCHEDULE_TIMEOUT
)
328 end_jiffies
+= port
->baud
?(2 * rcib
* 10 * HZ
/ port
->baud
):0;
329 end_jiffies
+= timeout
;
331 gs_dprintk (GS_DEBUG_FLUSH
, "now=%lx, end=%lx (%ld).\n",
332 jiffies
, end_jiffies
, end_jiffies
-jiffies
);
334 /* the expression is actually jiffies < end_jiffies, but that won't
335 work around the wraparound. Tricky eh? */
336 while ((charsleft
= gs_real_chars_in_buffer (port
->tty
)) &&
337 time_after (end_jiffies
, jiffies
)) {
339 chars * (bits/char) * (jiffies /sec) / (bits/sec) = jiffies!
342 charsleft
+= 16; /* Allow 16 chars more to be transmitted ... */
343 jiffies_to_transmit
= port
->baud
?(1 + charsleft
* 10 * HZ
/ port
->baud
):0;
344 /* ^^^ Round up.... */
345 if (jiffies_to_transmit
<= 0) jiffies_to_transmit
= 1;
347 gs_dprintk (GS_DEBUG_FLUSH
, "Expect to finish in %d jiffies "
348 "(%d chars).\n", jiffies_to_transmit
, charsleft
);
350 msleep_interruptible(jiffies_to_msecs(jiffies_to_transmit
));
351 if (signal_pending (current
)) {
352 gs_dprintk (GS_DEBUG_FLUSH
, "Signal pending. Bombing out: ");
358 gs_dprintk (GS_DEBUG_FLUSH
, "charsleft = %d.\n", charsleft
);
359 set_current_state (TASK_RUNNING
);
367 void gs_flush_buffer(struct tty_struct
*tty
)
369 struct gs_port
*port
;
376 port
= tty
->driver_data
;
380 /* XXX Would the write semaphore do? */
381 spin_lock_irqsave (&port
->driver_lock
, flags
);
382 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
383 spin_unlock_irqrestore (&port
->driver_lock
, flags
);
390 void gs_flush_chars(struct tty_struct
* tty
)
392 struct gs_port
*port
;
398 port
= tty
->driver_data
;
402 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
408 /* Beats me -- REW */
409 port
->flags
|= GS_TX_INTEN
;
410 port
->rd
->enable_tx_interrupts (port
);
415 void gs_stop(struct tty_struct
* tty
)
417 struct gs_port
*port
;
423 port
= tty
->driver_data
;
427 if (port
->xmit_cnt
&&
429 (port
->flags
& GS_TX_INTEN
) ) {
430 port
->flags
&= ~GS_TX_INTEN
;
431 port
->rd
->disable_tx_interrupts (port
);
437 void gs_start(struct tty_struct
* tty
)
439 struct gs_port
*port
;
443 port
= tty
->driver_data
;
447 if (port
->xmit_cnt
&&
449 !(port
->flags
& GS_TX_INTEN
) ) {
450 port
->flags
|= GS_TX_INTEN
;
451 port
->rd
->enable_tx_interrupts (port
);
457 static void gs_shutdown_port (struct gs_port
*port
)
465 if (!(port
->flags
& ASYNC_INITIALIZED
))
468 spin_lock_irqsave(&port
->driver_lock
, flags
);
470 if (port
->xmit_buf
) {
471 free_page((unsigned long) port
->xmit_buf
);
472 port
->xmit_buf
= NULL
;
476 set_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
478 port
->rd
->shutdown_port (port
);
480 port
->flags
&= ~ASYNC_INITIALIZED
;
481 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
487 void gs_hangup(struct tty_struct
*tty
)
489 struct gs_port
*port
;
495 port
= tty
->driver_data
;
500 gs_shutdown_port (port
);
501 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|GS_ACTIVE
);
505 wake_up_interruptible(&port
->open_wait
);
510 int gs_block_til_ready(void *port_
, struct file
* filp
)
512 struct gs_port
*port
= port_
;
513 DECLARE_WAITQUEUE(wait
, current
);
517 struct tty_struct
*tty
;
528 gs_dprintk (GS_DEBUG_BTR
, "Entering gs_block_till_ready.\n");
530 * If the device is in the middle of being closed, then block
531 * until it's done, and then try again.
533 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
534 interruptible_sleep_on(&port
->close_wait
);
535 if (port
->flags
& ASYNC_HUP_NOTIFY
)
541 gs_dprintk (GS_DEBUG_BTR
, "after hung up\n");
544 * If non-blocking mode is set, or the port is not enabled,
545 * then make the check up front and then exit.
547 if ((filp
->f_flags
& O_NONBLOCK
) ||
548 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
549 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
553 gs_dprintk (GS_DEBUG_BTR
, "after nonblock\n");
559 * Block waiting for the carrier detect and the line to become
560 * free (i.e., not in use by the callout). While we are in
561 * this loop, port->count is dropped by one, so that
562 * rs_close() knows when to free things. We restore it upon
563 * exit, either normal or abnormal.
567 add_wait_queue(&port
->open_wait
, &wait
);
569 gs_dprintk (GS_DEBUG_BTR
, "after add waitq.\n");
570 spin_lock_irqsave(&port
->driver_lock
, flags
);
571 if (!tty_hung_up_p(filp
)) {
574 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
575 port
->blocked_open
++;
577 CD
= port
->rd
->get_CD (port
);
578 gs_dprintk (GS_DEBUG_BTR
, "CD is now %d.\n", CD
);
579 set_current_state (TASK_INTERRUPTIBLE
);
580 if (tty_hung_up_p(filp
) ||
581 !(port
->flags
& ASYNC_INITIALIZED
)) {
582 if (port
->flags
& ASYNC_HUP_NOTIFY
)
585 retval
= -ERESTARTSYS
;
588 if (!(port
->flags
& ASYNC_CLOSING
) &&
591 gs_dprintk (GS_DEBUG_BTR
, "signal_pending is now: %d (%lx)\n",
592 (int)signal_pending (current
), *(long*)(¤t
->blocked
));
593 if (signal_pending(current
)) {
594 retval
= -ERESTARTSYS
;
599 gs_dprintk (GS_DEBUG_BTR
, "Got out of the loop. (%d)\n",
601 set_current_state (TASK_RUNNING
);
602 remove_wait_queue(&port
->open_wait
, &wait
);
603 if (!tty_hung_up_p(filp
)) {
606 port
->blocked_open
--;
610 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
616 void gs_close(struct tty_struct
* tty
, struct file
* filp
)
619 struct gs_port
*port
;
625 port
= (struct gs_port
*) tty
->driver_data
;
630 /* This seems to happen when this is called from vhangup. */
631 gs_dprintk (GS_DEBUG_CLOSE
, "gs: Odd: port->tty is NULL\n");
635 spin_lock_irqsave(&port
->driver_lock
, flags
);
637 if (tty_hung_up_p(filp
)) {
638 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
639 if (port
->rd
->hungup
)
640 port
->rd
->hungup (port
);
645 if ((tty
->count
== 1) && (port
->count
!= 1)) {
646 printk(KERN_ERR
"gs: gs_close port %p: bad port count;"
647 " tty->count is 1, port count is %d\n", port
, port
->count
);
650 if (--port
->count
< 0) {
651 printk(KERN_ERR
"gs: gs_close port %p: bad port count: %d\n", port
, port
->count
);
656 gs_dprintk(GS_DEBUG_CLOSE
, "gs_close port %p: count: %d\n", port
, port
->count
);
657 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
661 port
->flags
|= ASYNC_CLOSING
;
664 * Now we wait for the transmit buffer to clear; and we notify
665 * the line discipline to only process XON/XOFF characters.
668 /* if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
669 tty_wait_until_sent(tty, port->closing_wait); */
672 * At this point we stop accepting input. To do this, we
673 * disable the receive line status interrupts, and tell the
674 * interrupt driver to stop checking the data ready bit in the
675 * line status register.
678 port
->rd
->disable_rx_interrupts (port
);
679 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
681 /* close has no way of returning "EINTR", so discard return value */
682 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
683 gs_wait_tx_flushed (port
, port
->closing_wait
);
685 port
->flags
&= ~GS_ACTIVE
;
687 if (tty
->driver
->flush_buffer
)
688 tty
->driver
->flush_buffer(tty
);
690 tty_ldisc_flush(tty
);
694 port
->rd
->close (port
);
695 port
->rd
->shutdown_port (port
);
698 if (port
->blocked_open
) {
699 if (port
->close_delay
) {
700 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
701 msleep_interruptible(jiffies_to_msecs(port
->close_delay
));
702 spin_lock_irqsave(&port
->driver_lock
, flags
);
704 wake_up_interruptible(&port
->open_wait
);
706 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
| ASYNC_INITIALIZED
);
707 wake_up_interruptible(&port
->close_wait
);
713 static unsigned int gs_baudrates
[] = {
714 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
715 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
719 void gs_set_termios (struct tty_struct
* tty
,
720 struct ktermios
* old_termios
)
722 struct gs_port
*port
;
723 int baudrate
, tmp
, rv
;
724 struct ktermios
*tiosp
;
730 port
= tty
->driver_data
;
734 /* This seems to happen when this is called after gs_close. */
735 gs_dprintk (GS_DEBUG_TERMIOS
, "gs: Odd: port->tty is NULL\n");
740 tiosp
= tty
->termios
;
742 if (gs_debug
& GS_DEBUG_TERMIOS
) {
743 gs_dprintk (GS_DEBUG_TERMIOS
, "termios structure (%p):\n", tiosp
);
746 /* This is an optimization that is only allowed for dumb cards */
747 /* Smart cards require knowledge of iflags and oflags too: that
748 might change hardware cooking mode.... */
750 if( (tiosp
->c_iflag
== old_termios
->c_iflag
)
751 && (tiosp
->c_oflag
== old_termios
->c_oflag
)
752 && (tiosp
->c_cflag
== old_termios
->c_cflag
)
753 && (tiosp
->c_lflag
== old_termios
->c_lflag
)
754 && (tiosp
->c_line
== old_termios
->c_line
)
755 && (memcmp(tiosp
->c_cc
, old_termios
->c_cc
, NCC
) == 0)) {
756 gs_dprintk(GS_DEBUG_TERMIOS
, "gs_set_termios: optimized away\n");
760 gs_dprintk(GS_DEBUG_TERMIOS
, "gs_set_termios: no old_termios: "
761 "no optimization\n");
763 if(old_termios
&& (gs_debug
& GS_DEBUG_TERMIOS
)) {
764 if(tiosp
->c_iflag
!= old_termios
->c_iflag
) printk("c_iflag changed\n");
765 if(tiosp
->c_oflag
!= old_termios
->c_oflag
) printk("c_oflag changed\n");
766 if(tiosp
->c_cflag
!= old_termios
->c_cflag
) printk("c_cflag changed\n");
767 if(tiosp
->c_lflag
!= old_termios
->c_lflag
) printk("c_lflag changed\n");
768 if(tiosp
->c_line
!= old_termios
->c_line
) printk("c_line changed\n");
769 if(!memcmp(tiosp
->c_cc
, old_termios
->c_cc
, NCC
)) printk("c_cc changed\n");
772 baudrate
= tty_get_baud_rate(tty
);
774 baudrate
= gs_baudrates
[baudrate
];
775 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
776 if ( (port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
778 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
780 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
782 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
784 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
785 baudrate
= (port
->baud_base
/ port
->custom_divisor
);
788 /* I recommend using THIS instead of the mess in termios (and
789 duplicating the above code). Next we should create a clean
790 interface towards this variable. If your card supports arbitrary
791 baud rates, (e.g. CD1400 or 16550 based cards) then everything
792 will be very easy..... */
793 port
->baud
= baudrate
;
795 /* Two timer ticks seems enough to wakeup something like SLIP driver */
796 /* Baudrate/10 is cps. Divide by HZ to get chars per tick. */
797 tmp
= (baudrate
/ 10 / HZ
) * 2;
799 if (tmp
< 0) tmp
= 0;
800 if (tmp
>= SERIAL_XMIT_SIZE
) tmp
= SERIAL_XMIT_SIZE
-1;
802 port
->wakeup_chars
= tmp
;
804 /* We should really wait for the characters to be all sent before
805 changing the settings. -- CAL */
806 rv
= gs_wait_tx_flushed (port
, MAX_SCHEDULE_TIMEOUT
);
807 if (rv
< 0) return /* rv */;
809 rv
= port
->rd
->set_real_termios(port
);
810 if (rv
< 0) return /* rv */;
813 (old_termios
->c_cflag
& CRTSCTS
)) &&
814 !( tiosp
->c_cflag
& CRTSCTS
)) {
819 #ifdef tytso_patch_94Nov25_1726
820 /* This "makes sense", Why is it commented out? */
822 if (!(old_termios
->c_cflag
& CLOCAL
) &&
823 (tty
->termios
->c_cflag
& CLOCAL
))
824 wake_up_interruptible(&port
->gs
.open_wait
);
833 /* Must be called with interrupts enabled */
834 int gs_init_port(struct gs_port
*port
)
840 if (port
->flags
& ASYNC_INITIALIZED
) {
844 if (!port
->xmit_buf
) {
845 /* We may sleep in get_zeroed_page() */
848 tmp
= get_zeroed_page(GFP_KERNEL
);
849 spin_lock_irqsave (&port
->driver_lock
, flags
);
853 port
->xmit_buf
= (unsigned char *) tmp
;
854 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
855 if (!port
->xmit_buf
) {
861 spin_lock_irqsave (&port
->driver_lock
, flags
);
863 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
864 mutex_init(&port
->port_write_mutex
);
865 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
866 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
867 gs_set_termios(port
->tty
, NULL
);
868 spin_lock_irqsave (&port
->driver_lock
, flags
);
869 port
->flags
|= ASYNC_INITIALIZED
;
870 port
->flags
&= ~GS_TX_INTEN
;
872 spin_unlock_irqrestore(&port
->driver_lock
, flags
);
878 int gs_setserial(struct gs_port
*port
, struct serial_struct __user
*sp
)
880 struct serial_struct sio
;
882 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
885 if (!capable(CAP_SYS_ADMIN
)) {
886 if ((sio
.baud_base
!= port
->baud_base
) ||
887 (sio
.close_delay
!= port
->close_delay
) ||
888 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
889 (port
->flags
& ~ASYNC_USR_MASK
)))
893 port
->flags
= (port
->flags
& ~ASYNC_USR_MASK
) |
894 (sio
.flags
& ASYNC_USR_MASK
);
896 port
->baud_base
= sio
.baud_base
;
897 port
->close_delay
= sio
.close_delay
;
898 port
->closing_wait
= sio
.closing_wait
;
899 port
->custom_divisor
= sio
.custom_divisor
;
901 gs_set_termios (port
->tty
, NULL
);
907 /*****************************************************************************/
910 * Generate the serial struct info.
913 int gs_getserial(struct gs_port
*port
, struct serial_struct __user
*sp
)
915 struct serial_struct sio
;
917 memset(&sio
, 0, sizeof(struct serial_struct
));
918 sio
.flags
= port
->flags
;
919 sio
.baud_base
= port
->baud_base
;
920 sio
.close_delay
= port
->close_delay
;
921 sio
.closing_wait
= port
->closing_wait
;
922 sio
.custom_divisor
= port
->custom_divisor
;
925 /* If you want you can override these. */
926 sio
.type
= PORT_UNKNOWN
;
927 sio
.xmit_fifo_size
= -1;
932 if (port
->rd
->getserial
)
933 port
->rd
->getserial (port
, &sio
);
935 if (copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)))
942 void gs_got_break(struct gs_port
*port
)
946 tty_insert_flip_char(port
->tty
, 0, TTY_BREAK
);
947 tty_schedule_flip(port
->tty
);
948 if (port
->flags
& ASYNC_SAK
) {
956 EXPORT_SYMBOL(gs_put_char
);
957 EXPORT_SYMBOL(gs_write
);
958 EXPORT_SYMBOL(gs_write_room
);
959 EXPORT_SYMBOL(gs_chars_in_buffer
);
960 EXPORT_SYMBOL(gs_flush_buffer
);
961 EXPORT_SYMBOL(gs_flush_chars
);
962 EXPORT_SYMBOL(gs_stop
);
963 EXPORT_SYMBOL(gs_start
);
964 EXPORT_SYMBOL(gs_hangup
);
965 EXPORT_SYMBOL(gs_block_til_ready
);
966 EXPORT_SYMBOL(gs_close
);
967 EXPORT_SYMBOL(gs_set_termios
);
968 EXPORT_SYMBOL(gs_init_port
);
969 EXPORT_SYMBOL(gs_setserial
);
970 EXPORT_SYMBOL(gs_getserial
);
971 EXPORT_SYMBOL(gs_got_break
);
973 MODULE_LICENSE("GPL");