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.
17 #include <linux/tty.h>
18 #include <linux/serial.h>
20 #include <asm/semaphore.h>
21 #include <asm/uaccess.h>
22 #include <linux/version.h>
23 #include <linux/module.h>
24 #include <linux/generic_serial.h>
28 static char * tmp_buf
;
29 static DECLARE_MUTEX(tmp_buf_sem
);
35 #define gs_dprintk(f, str...) if (gs_debug & f) printk (str)
37 #define gs_dprintk(f, str...) /* nothing */
40 #define func_enter() gs_dprintk (GS_DEBUG_FLOW, "gs: enter " __FUNCTION__ "\n")
41 #define func_exit() gs_dprintk (GS_DEBUG_FLOW, "gs: exit " __FUNCTION__ "\n")
44 #define DECL /* Nothing */
45 #define LOCKIT down (& port->port_write_sem);
46 #define RELEASEIT up (&port->port_write_sem);
48 #define DECL unsigned long flags;
49 #define LOCKIT save_flags (flags);cli ()
50 #define RELEASEIT restore_flags (flags)
53 #define RS_EVENT_WRITE_WAKEUP 1
56 MODULE_PARM(gs_debug
, "i");
60 static void my_hd (unsigned char *addr
, int len
)
64 for (i
=0;i
<len
;i
+=16) {
65 printk ("%08x ", (int) addr
+i
);
67 printk ("%02x %s", addr
[j
+i
], (j
==7)?" ":"");
71 printk ("%c", (ch
< 0x20)?'.':((ch
> 0x7f)?'.':ch
));
77 #define my_hd(addr,len)
81 void gs_put_char(struct tty_struct
* tty
, unsigned char ch
)
83 struct gs_port
*port
= tty
->driver_data
;
88 /* Take a lock on the serial tranmit buffer! */
91 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
92 /* Sorry, buffer is full, drop character. Update statistics???? -- REW */
97 port
->xmit_buf
[port
->xmit_head
++] = ch
;
98 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
99 port
->xmit_cnt
++; /* Characters in buffer */
106 #ifdef NEW_WRITE_LOCKING
109 > Problems to take into account are:
110 > -1- Interrupts that empty part of the buffer.
111 > -2- page faults on the access to userspace.
112 > -3- Other processes that are also trying to do a "write".
115 int gs_write(struct tty_struct
* tty
, int from_user
,
116 const unsigned char *buf
, int count
)
118 struct gs_port
*port
= tty
->driver_data
;
124 if (! (port
->flags
& ASYNC_INITIALIZED
))
127 /* get exclusive "write" access to this port (problem 3) */
128 /* This is not a spinlock because we can have a disk access (page
129 fault) in copy_from_user */
130 down (& port
->port_write_sem
);
136 /* This is safe because we "OWN" the "head". Noone else can
137 change the "head": we own the port_write_sem. */
138 /* Don't overrun the end of the buffer */
139 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
142 /* This is safe because the xmit_cnt can only decrease. This
143 would increase "t", so we might copy too little chars. */
144 /* Don't copy past the "head" of the buffer */
145 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
148 /* Can't copy more? break out! */
151 copy_from_user (port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
153 memcpy (port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
155 port
-> xmit_cnt
+= c
;
156 port
-> xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
161 up (& port
->port_write_sem
);
163 gs_dprintk (GS_DEBUG_WRITE
, "write: interrupts are %s\n",
164 (port
->flags
& GS_TX_INTEN
)?"enabled": "disabled");
166 if (port
->xmit_cnt
&&
169 !(port
->flags
& GS_TX_INTEN
)) {
170 port
->flags
|= GS_TX_INTEN
;
171 port
->rd
->enable_tx_interrupts (port
);
178 > Problems to take into account are:
179 > -1- Interrupts that empty part of the buffer.
180 > -2- page faults on the access to userspace.
181 > -3- Other processes that are also trying to do a "write".
184 int gs_write(struct tty_struct
* tty
, int from_user
,
185 const unsigned char *buf
, int count
)
187 struct gs_port
*port
;
194 /* The standard serial driver returns 0 in this case.
195 That sounds to me as "No error, I just didn't get to writing any
196 bytes. Feel free to try again."
197 The "official" way to write n bytes from buf is:
199 for (nwritten = 0;nwritten < n;nwritten += rv) {
200 rv = write (fd, buf+nwritten, n-nwritten);
201 if (rv < 0) break; // Error: bail out. //
204 which will loop endlessly in this case. The manual page for write
205 agrees with me. In practise almost everybody writes
206 "write (fd, buf,n);" but some people might have had to deal with
207 incomplete writes in the past and correctly implemented it by now...
210 if (!tty
) return -EIO
;
212 port
= tty
->driver_data
;
213 if (!port
|| !port
->xmit_buf
|| !tmp_buf
)
222 /* This is safe because we "OWN" the "head". Noone else can
223 change the "head": we own the port_write_sem. */
224 /* Don't overrun the end of the buffer */
225 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
228 /* This is safe because the xmit_cnt can only decrease. This
229 would increase "t", so we might copy too little chars. */
230 /* Don't copy past the "head" of the buffer */
231 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
234 /* Can't copy more? break out! */
237 c
-= copy_from_user(tmp_buf
, buf
, c
);
244 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
246 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
249 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, c
);
250 port
->xmit_head
= ((port
->xmit_head
+ c
) &
251 (SERIAL_XMIT_SIZE
-1));
253 restore_flags(flags
);
264 /* This is safe because we "OWN" the "head". Noone else can
265 change the "head": we own the port_write_sem. */
266 /* Don't overrun the end of the buffer */
267 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
270 /* This is safe because the xmit_cnt can only decrease. This
271 would increase "t", so we might copy too little chars. */
272 /* Don't copy past the "head" of the buffer */
273 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
276 /* Can't copy more? break out! */
278 restore_flags(flags
);
281 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
282 port
->xmit_head
= ((port
->xmit_head
+ c
) &
283 (SERIAL_XMIT_SIZE
-1));
285 restore_flags(flags
);
292 if (port
->xmit_cnt
&&
295 !(port
->flags
& GS_TX_INTEN
)) {
296 port
->flags
|= GS_TX_INTEN
;
297 port
->rd
->enable_tx_interrupts (port
);
307 int gs_write_room(struct tty_struct
* tty
)
309 struct gs_port
*port
= tty
->driver_data
;
313 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
321 int gs_chars_in_buffer(struct tty_struct
*tty
)
323 struct gs_port
*port
= tty
->driver_data
;
327 return port
->xmit_cnt
;
331 int gs_real_chars_in_buffer(struct tty_struct
*tty
)
333 struct gs_port
*port
;
337 port
= tty
->driver_data
;
339 if (!port
->rd
) return 0;
340 if (!port
->rd
->chars_in_buffer
) return 0;
343 return port
->xmit_cnt
+ port
->rd
->chars_in_buffer (port
);
347 static int gs_wait_tx_flushed (void * ptr
, int timeout
)
349 struct gs_port
*port
= ptr
;
351 int jiffies_to_transmit
, charsleft
= 0, rv
= 0;
356 gs_dprintk (GS_DEBUG_FLUSH
, "port=%p.\n", port
);
358 gs_dprintk (GS_DEBUG_FLUSH
, "xmit_cnt=%x, xmit_buf=%p, tty=%p.\n",
359 port
->xmit_cnt
, port
->xmit_buf
, port
->tty
);
362 if (!port
|| port
->xmit_cnt
< 0 || !port
->xmit_buf
) {
363 gs_dprintk (GS_DEBUG_FLUSH
, "ERROR: !port, !port->xmit_buf or prot->xmit_cnt < 0.\n");
365 return -EINVAL
; /* This is an error which we don't know how to handle. */
368 rcib
= gs_real_chars_in_buffer(port
->tty
);
371 gs_dprintk (GS_DEBUG_FLUSH
, "nothing to wait for.\n");
375 /* stop trying: now + twice the time it would normally take + seconds */
376 end_jiffies
= jiffies
;
377 if (timeout
!= MAX_SCHEDULE_TIMEOUT
)
378 end_jiffies
+= port
->baud
?(2 * rcib
* 10 * HZ
/ port
->baud
):0;
379 end_jiffies
+= timeout
;
381 gs_dprintk (GS_DEBUG_FLUSH
, "now=%lx, end=%lx (%ld).\n",
382 jiffies
, end_jiffies
, end_jiffies
-jiffies
);
385 /* the expression is actually jiffies < end_jiffies, but that won't
386 work around the wraparound. Tricky eh? */
388 (charsleft
= gs_real_chars_in_buffer (port
->tty
)) &&
389 time_after (end_jiffies
, jiffies
)) {
391 chars * (bits/char) * (jiffies /sec) / (bits/sec) = jiffies!
394 charsleft
+= 16; /* Allow 16 chars more to be transmitted ... */
395 jiffies_to_transmit
= port
->baud
?(1 + charsleft
* 10 * HZ
/ port
->baud
):0;
396 /* ^^^ Round up.... */
397 if (jiffies_to_transmit
<= 0) jiffies_to_transmit
= 1;
399 gs_dprintk (GS_DEBUG_FLUSH
, "Expect to finish in %d jiffies "
400 "(%d chars).\n", jiffies_to_transmit
, charsleft
);
402 current
->state
= TASK_INTERRUPTIBLE
;
403 schedule_timeout(jiffies_to_transmit
);
404 if (signal_pending (current
)) {
405 gs_dprintk (GS_DEBUG_FLUSH
, "Signal pending. Bombing out: ");
411 gs_dprintk (GS_DEBUG_FLUSH
, "charsleft = %d.\n", charsleft
);
412 current
->state
= TASK_RUNNING
;
420 void gs_flush_buffer(struct tty_struct
*tty
)
422 struct gs_port
*port
= tty
->driver_data
;
426 /* XXX Would the write semaphore do? */
427 save_flags(flags
); cli();
428 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
429 restore_flags(flags
);
431 wake_up_interruptible(&tty
->write_wait
);
432 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
433 tty
->ldisc
.write_wakeup
)
434 (tty
->ldisc
.write_wakeup
)(tty
);
439 void gs_flush_chars(struct tty_struct
* tty
)
441 struct gs_port
*port
= tty
->driver_data
;
444 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
450 /* Beats me -- REW */
451 port
->flags
|= GS_TX_INTEN
;
452 port
->rd
->enable_tx_interrupts (port
);
457 void gs_stop(struct tty_struct
* tty
)
459 struct gs_port
*port
= tty
->driver_data
;
462 if (port
->xmit_cnt
&&
464 (port
->flags
& GS_TX_INTEN
) ) {
465 port
->flags
&= ~GS_TX_INTEN
;
466 port
->rd
->disable_tx_interrupts (port
);
472 void gs_start(struct tty_struct
* tty
)
474 struct gs_port
*port
= tty
->driver_data
;
476 if (port
->xmit_cnt
&&
478 !(port
->flags
& GS_TX_INTEN
) ) {
479 port
->flags
|= GS_TX_INTEN
;
480 port
->rd
->enable_tx_interrupts (port
);
486 void gs_shutdown_port (struct gs_port
*port
)
490 if (!(port
->flags
& ASYNC_INITIALIZED
))
496 if (port
->xmit_buf
) {
497 free_page((unsigned long) port
->xmit_buf
);
502 set_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
504 port
->rd
->shutdown_port (port
);
506 port
->flags
&= ~ASYNC_INITIALIZED
;
507 restore_flags (flags
);
512 void gs_hangup(struct tty_struct
*tty
)
514 struct gs_port
*port
= tty
->driver_data
;
522 gs_shutdown_port (port
);
523 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|GS_ACTIVE
);
527 wake_up_interruptible(&port
->open_wait
);
532 void gs_do_softint(void *private_
)
534 struct gs_port
*port
= private_
;
535 struct tty_struct
*tty
;
540 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
)) {
541 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
542 tty
->ldisc
.write_wakeup
)
543 (tty
->ldisc
.write_wakeup
)(tty
);
544 wake_up_interruptible(&tty
->write_wait
);
550 int block_til_ready(void *port_
, struct file
* filp
)
552 struct gs_port
*port
= port_
;
553 DECLARE_WAITQUEUE(wait
, current
);
557 struct tty_struct
*tty
;
562 gs_dprintk (GS_DEBUG_BTR
, "Entering block_till_ready.\n");
564 * If the device is in the middle of being closed, then block
565 * until it's done, and then try again.
567 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
568 interruptible_sleep_on(&port
->close_wait
);
569 if (port
->flags
& ASYNC_HUP_NOTIFY
)
574 gs_dprintk (GS_DEBUG_BTR
, "after hung up\n");
577 * If this is a callout device, then just make sure the normal
578 * device isn't being used.
580 if (tty
->driver
.subtype
== GS_TYPE_CALLOUT
) {
581 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
583 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
584 (port
->flags
& ASYNC_SESSION_LOCKOUT
) &&
585 (port
->session
!= current
->session
))
587 if ((port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
588 (port
->flags
& ASYNC_PGRP_LOCKOUT
) &&
589 (port
->pgrp
!= current
->pgrp
))
591 port
->flags
|= ASYNC_CALLOUT_ACTIVE
;
595 gs_dprintk (GS_DEBUG_BTR
, "after subtype\n");
597 * If non-blocking mode is set, or the port is not enabled,
598 * then make the check up front and then exit.
600 if ((filp
->f_flags
& O_NONBLOCK
) ||
601 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
602 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
604 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
608 gs_dprintk (GS_DEBUG_BTR
, "after nonblock\n");
609 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
) {
610 if (port
->normal_termios
.c_cflag
& CLOCAL
)
617 gs_dprintk (GS_DEBUG_BTR
, "after clocal check.\n");
619 * Block waiting for the carrier detect and the line to become
620 * free (i.e., not in use by the callout). While we are in
621 * this loop, port->count is dropped by one, so that
622 * rs_close() knows when to free things. We restore it upon
623 * exit, either normal or abnormal.
627 add_wait_queue(&port
->open_wait
, &wait
);
629 gs_dprintk (GS_DEBUG_BTR
, "after add waitq.\n");
631 if (!tty_hung_up_p(filp
))
634 port
->blocked_open
++;
636 CD
= port
->rd
->get_CD (port
);
637 gs_dprintk (GS_DEBUG_BTR
, "CD is now %d.\n", CD
);
638 set_current_state(TASK_INTERRUPTIBLE
);
639 if (tty_hung_up_p(filp
) ||
640 !(port
->flags
& ASYNC_INITIALIZED
)) {
641 if (port
->flags
& ASYNC_HUP_NOTIFY
)
644 retval
= -ERESTARTSYS
;
647 if (!(port
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
648 !(port
->flags
& ASYNC_CLOSING
) &&
651 gs_dprintk (GS_DEBUG_BTR
, "signal_pending is now: %d (%lx)\n",
652 (int)signal_pending (current
), *(long*)(¤t
->blocked
));
653 if (signal_pending(current
)) {
654 retval
= -ERESTARTSYS
;
659 gs_dprintk (GS_DEBUG_BTR
, "Got out of the loop. (%d)\n",
661 set_current_state (TASK_RUNNING
);
662 remove_wait_queue(&port
->open_wait
, &wait
);
663 if (!tty_hung_up_p(filp
))
665 port
->blocked_open
--;
669 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
675 void gs_close(struct tty_struct
* tty
, struct file
* filp
)
678 struct gs_port
*port
;
682 port
= (struct gs_port
*) tty
->driver_data
;
690 /* This seems to happen when this is called from vhangup. */
691 gs_dprintk (GS_DEBUG_CLOSE
, "gs: Odd: port->tty is NULL\n");
695 save_flags(flags
); cli();
696 if (tty_hung_up_p(filp
)) {
697 restore_flags(flags
);
698 port
->rd
->hungup (port
);
703 if ((tty
->count
== 1) && (port
->count
!= 1)) {
704 printk(KERN_ERR
"gs: gs_close: bad port count;"
705 " tty->count is 1, port count is %d\n", port
->count
);
708 if (--port
->count
< 0) {
709 printk(KERN_ERR
"gs: gs_close: bad port count: %d\n", port
->count
);
713 gs_dprintk(GS_DEBUG_CLOSE
, "gs_close: count: %d\n", port
->count
);
714 restore_flags(flags
);
718 port
->flags
|= ASYNC_CLOSING
;
721 * Save the termios structure, since this port may have
722 * separate termios for callout and dialin.
724 if (port
->flags
& ASYNC_NORMAL_ACTIVE
)
725 port
->normal_termios
= *tty
->termios
;
726 if (port
->flags
& ASYNC_CALLOUT_ACTIVE
)
727 port
->callout_termios
= *tty
->termios
;
729 * Now we wait for the transmit buffer to clear; and we notify
730 * the line discipline to only process XON/XOFF characters.
733 /* if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
734 tty_wait_until_sent(tty, port->closing_wait); */
737 * At this point we stop accepting input. To do this, we
738 * disable the receive line status interrupts, and tell the
739 * interrupt driver to stop checking the data ready bit in the
740 * line status register.
743 port
->rd
->disable_rx_interrupts (port
);
745 /* close has no way of returning "EINTR", so discard return value */
746 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
747 gs_wait_tx_flushed (port
, port
->closing_wait
);
749 port
->flags
&= ~GS_ACTIVE
;
751 if (tty
->driver
.flush_buffer
)
752 tty
->driver
.flush_buffer(tty
);
753 if (tty
->ldisc
.flush_buffer
)
754 tty
->ldisc
.flush_buffer(tty
);
758 port
->rd
->close (port
);
759 port
->rd
->shutdown_port (port
);
762 if (port
->blocked_open
) {
763 if (port
->close_delay
) {
764 current
->state
= TASK_INTERRUPTIBLE
;
765 schedule_timeout(port
->close_delay
);
767 wake_up_interruptible(&port
->open_wait
);
769 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
770 ASYNC_CLOSING
| ASYNC_INITIALIZED
);
771 wake_up_interruptible(&port
->close_wait
);
773 restore_flags(flags
);
778 static unsigned int gs_baudrates
[] = {
779 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
780 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
784 void gs_set_termios (struct tty_struct
* tty
,
785 struct termios
* old_termios
)
787 struct gs_port
*port
= tty
->driver_data
;
788 int baudrate
, tmp
, rv
;
789 struct termios
*tiosp
;
793 tiosp
= tty
->termios
;
796 if (gs_debug
& GS_DEBUG_TERMIOS
) {
797 gs_dprintk (GS_DEBUG_TERMIOS
, "termios structure (%p):\n", tiosp
);
801 /* This is an optimization that is only allowed for dumb cards */
802 /* Smart cards require knowledge of iflags and oflags too: that
803 might change hardware cooking mode.... */
806 if( (tiosp
->c_iflag
== old_termios
->c_iflag
)
807 && (tiosp
->c_oflag
== old_termios
->c_oflag
)
808 && (tiosp
->c_cflag
== old_termios
->c_cflag
)
809 && (tiosp
->c_lflag
== old_termios
->c_lflag
)
810 && (tiosp
->c_line
== old_termios
->c_line
)
811 && (memcmp(tiosp
->c_cc
, old_termios
->c_cc
, NCC
) == 0)) {
812 gs_dprintk(GS_DEBUG_TERMIOS
, "gs_set_termios: optimized away\n");
816 gs_dprintk(GS_DEBUG_TERMIOS
, "gs_set_termios: no old_termios: "
817 "no optimization\n");
819 if(old_termios
&& (gs_debug
& GS_DEBUG_TERMIOS
)) {
820 if(tiosp
->c_iflag
!= old_termios
->c_iflag
) printk("c_iflag changed\n");
821 if(tiosp
->c_oflag
!= old_termios
->c_oflag
) printk("c_oflag changed\n");
822 if(tiosp
->c_cflag
!= old_termios
->c_cflag
) printk("c_cflag changed\n");
823 if(tiosp
->c_lflag
!= old_termios
->c_lflag
) printk("c_lflag changed\n");
824 if(tiosp
->c_line
!= old_termios
->c_line
) printk("c_line changed\n");
825 if(!memcmp(tiosp
->c_cc
, old_termios
->c_cc
, NCC
)) printk("c_cc changed\n");
828 baudrate
= tiosp
->c_cflag
& CBAUD
;
829 if (baudrate
& CBAUDEX
) {
830 baudrate
&= ~CBAUDEX
;
831 if ((baudrate
< 1) || (baudrate
> 4))
832 tiosp
->c_cflag
&= ~CBAUDEX
;
837 baudrate
= gs_baudrates
[baudrate
];
838 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
839 if ( (port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
841 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
843 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
845 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
847 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
848 baudrate
= (port
->baud_base
/ port
->custom_divisor
);
851 /* I recommend using THIS instead of the mess in termios (and
852 duplicating the above code). Next we should create a clean
853 interface towards this variable. If your card supports arbitrary
854 baud rates, (e.g. CD1400 or 16550 based cards) then everything
855 will be very easy..... */
856 port
->baud
= baudrate
;
858 /* Two timer ticks seems enough to wakeup something like SLIP driver */
859 /* Baudrate/10 is cps. Divide by HZ to get chars per tick. */
860 tmp
= (baudrate
/ 10 / HZ
) * 2;
862 if (tmp
< 0) tmp
= 0;
863 if (tmp
>= SERIAL_XMIT_SIZE
) tmp
= SERIAL_XMIT_SIZE
-1;
865 port
->wakeup_chars
= tmp
;
867 /* We should really wait for the characters to be all sent before
868 changing the settings. -- CAL */
869 rv
= gs_wait_tx_flushed (port
, MAX_SCHEDULE_TIMEOUT
);
870 if (rv
< 0) return /* rv */;
872 rv
= port
->rd
->set_real_termios(port
);
873 if (rv
< 0) return /* rv */;
876 (old_termios
->c_cflag
& CRTSCTS
)) &&
877 !( tiosp
->c_cflag
& CRTSCTS
)) {
882 #ifdef tytso_patch_94Nov25_1726
883 /* This "makes sense", Why is it commented out? */
885 if (!(old_termios
->c_cflag
& CLOCAL
) &&
886 (tty
->termios
->c_cflag
& CLOCAL
))
887 wake_up_interruptible(&info
->open_wait
);
896 /* Must be called with interrupts enabled */
897 int gs_init_port(struct gs_port
*port
)
904 page
= get_free_page(GFP_KERNEL
);
906 cli (); /* Don't expect this to make a difference. */
910 tmp_buf
= (unsigned char *) page
;
911 restore_flags (flags
);
918 if (port
->flags
& ASYNC_INITIALIZED
)
921 if (!port
->xmit_buf
) {
922 /* We may sleep in get_free_page() */
925 tmp
= get_free_page(GFP_KERNEL
);
932 port
->xmit_buf
= (unsigned char *) tmp
;
933 restore_flags (flags
);
942 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
944 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
946 gs_set_termios(port
->tty
, NULL
);
948 port
->flags
|= ASYNC_INITIALIZED
;
949 port
->flags
&= ~GS_TX_INTEN
;
951 restore_flags(flags
);
956 int gs_setserial(struct gs_port
*port
, struct serial_struct
*sp
)
958 struct serial_struct sio
;
960 copy_from_user(&sio
, sp
, sizeof(struct serial_struct
));
962 if (!capable(CAP_SYS_ADMIN
)) {
963 if ((sio
.baud_base
!= port
->baud_base
) ||
964 (sio
.close_delay
!= port
->close_delay
) ||
965 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
966 (port
->flags
& ~ASYNC_USR_MASK
)))
970 port
->flags
= (port
->flags
& ~ASYNC_USR_MASK
) |
971 (sio
.flags
& ASYNC_USR_MASK
);
973 port
->baud_base
= sio
.baud_base
;
974 port
->close_delay
= sio
.close_delay
;
975 port
->closing_wait
= sio
.closing_wait
;
976 port
->custom_divisor
= sio
.custom_divisor
;
978 gs_set_termios (port
->tty
, NULL
);
984 /*****************************************************************************/
987 * Generate the serial struct info.
990 void gs_getserial(struct gs_port
*port
, struct serial_struct
*sp
)
992 struct serial_struct sio
;
994 memset(&sio
, 0, sizeof(struct serial_struct
));
995 sio
.flags
= port
->flags
;
996 sio
.baud_base
= port
->baud_base
;
997 sio
.close_delay
= port
->close_delay
;
998 sio
.closing_wait
= port
->closing_wait
;
999 sio
.custom_divisor
= port
->custom_divisor
;
1002 /* If you want you can override these. */
1003 sio
.type
= PORT_UNKNOWN
;
1004 sio
.xmit_fifo_size
= -1;
1009 if (port
->rd
->getserial
)
1010 port
->rd
->getserial (port
, &sio
);
1012 copy_to_user(sp
, &sio
, sizeof(struct serial_struct
));
1017 int init_module (void)
1022 int cleanup_module (void)