2 * linux/drivers/char/core.c
4 * Driver core for serial ports
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
8 * Copyright 1999 ARM Limited
9 * Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/module.h>
26 #include <linux/tty.h>
27 #include <linux/slab.h>
28 #include <linux/init.h>
29 #include <linux/console.h>
30 #include <linux/proc_fs.h>
31 #include <linux/seq_file.h>
32 #include <linux/device.h>
33 #include <linux/serial.h> /* for serial_state and serial_icounter_struct */
34 #include <linux/serial_core.h>
35 #include <linux/delay.h>
36 #include <linux/mutex.h>
39 #include <asm/uaccess.h>
42 * This is used to lock changes in serial line configuration.
44 static DEFINE_MUTEX(port_mutex
);
47 * lockdep: port->lock is initialized in two places, but we
48 * want only one lock-class:
50 static struct lock_class_key port_lock_key
;
52 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
54 #ifdef CONFIG_SERIAL_CORE_CONSOLE
55 #define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line)
57 #define uart_console(port) (0)
60 static void uart_change_speed(struct tty_struct
*tty
, struct uart_state
*state
,
61 struct ktermios
*old_termios
);
62 static void __uart_wait_until_sent(struct uart_port
*port
, int timeout
);
63 static void uart_change_pm(struct uart_state
*state
, int pm_state
);
66 * This routine is used by the interrupt handler to schedule processing in
67 * the software interrupt portion of the driver.
69 void uart_write_wakeup(struct uart_port
*port
)
71 struct uart_state
*state
= port
->state
;
73 * This means you called this function _after_ the port was
74 * closed. No cookie for you.
77 tasklet_schedule(&state
->tlet
);
80 static void uart_stop(struct tty_struct
*tty
)
82 struct uart_state
*state
= tty
->driver_data
;
83 struct uart_port
*port
= state
->uart_port
;
86 spin_lock_irqsave(&port
->lock
, flags
);
87 port
->ops
->stop_tx(port
);
88 spin_unlock_irqrestore(&port
->lock
, flags
);
91 static void __uart_start(struct tty_struct
*tty
)
93 struct uart_state
*state
= tty
->driver_data
;
94 struct uart_port
*port
= state
->uart_port
;
96 if (!uart_circ_empty(&state
->xmit
) && state
->xmit
.buf
&&
97 !tty
->stopped
&& !tty
->hw_stopped
)
98 port
->ops
->start_tx(port
);
101 static void uart_start(struct tty_struct
*tty
)
103 struct uart_state
*state
= tty
->driver_data
;
104 struct uart_port
*port
= state
->uart_port
;
107 spin_lock_irqsave(&port
->lock
, flags
);
109 spin_unlock_irqrestore(&port
->lock
, flags
);
112 static void uart_tasklet_action(unsigned long data
)
114 struct uart_state
*state
= (struct uart_state
*)data
;
115 tty_wakeup(state
->port
.tty
);
119 uart_update_mctrl(struct uart_port
*port
, unsigned int set
, unsigned int clear
)
124 spin_lock_irqsave(&port
->lock
, flags
);
126 port
->mctrl
= (old
& ~clear
) | set
;
127 if (old
!= port
->mctrl
)
128 port
->ops
->set_mctrl(port
, port
->mctrl
);
129 spin_unlock_irqrestore(&port
->lock
, flags
);
132 #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0)
133 #define uart_clear_mctrl(port, clear) uart_update_mctrl(port, 0, clear)
136 * Startup the port. This will be called once per open. All calls
137 * will be serialised by the per-port mutex.
139 static int uart_startup(struct tty_struct
*tty
, struct uart_state
*state
, int init_hw
)
141 struct uart_port
*uport
= state
->uart_port
;
142 struct tty_port
*port
= &state
->port
;
146 if (port
->flags
& ASYNC_INITIALIZED
)
150 * Set the TTY IO error marker - we will only clear this
151 * once we have successfully opened the port. Also set
152 * up the tty->alt_speed kludge
154 set_bit(TTY_IO_ERROR
, &tty
->flags
);
156 if (uport
->type
== PORT_UNKNOWN
)
160 * Initialise and allocate the transmit and temporary
163 if (!state
->xmit
.buf
) {
164 /* This is protected by the per port mutex */
165 page
= get_zeroed_page(GFP_KERNEL
);
169 state
->xmit
.buf
= (unsigned char *) page
;
170 uart_circ_clear(&state
->xmit
);
173 retval
= uport
->ops
->startup(uport
);
175 if (uart_console(uport
) && uport
->cons
->cflag
) {
176 tty
->termios
->c_cflag
= uport
->cons
->cflag
;
177 uport
->cons
->cflag
= 0;
180 * Initialise the hardware port settings.
182 uart_change_speed(tty
, state
, NULL
);
186 * Setup the RTS and DTR signals once the
187 * port is open and ready to respond.
189 if (tty
->termios
->c_cflag
& CBAUD
)
190 uart_set_mctrl(uport
, TIOCM_RTS
| TIOCM_DTR
);
193 if (port
->flags
& ASYNC_CTS_FLOW
) {
194 spin_lock_irq(&uport
->lock
);
195 if (!(uport
->ops
->get_mctrl(uport
) & TIOCM_CTS
))
197 spin_unlock_irq(&uport
->lock
);
200 set_bit(ASYNCB_INITIALIZED
, &port
->flags
);
202 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
205 if (retval
&& capable(CAP_SYS_ADMIN
))
212 * This routine will shutdown a serial port; interrupts are disabled, and
213 * DTR is dropped if the hangup on close termio flag is on. Calls to
214 * uart_shutdown are serialised by the per-port semaphore.
216 static void uart_shutdown(struct tty_struct
*tty
, struct uart_state
*state
)
218 struct uart_port
*uport
= state
->uart_port
;
219 struct tty_port
*port
= &state
->port
;
222 * Set the TTY IO error marker
225 set_bit(TTY_IO_ERROR
, &tty
->flags
);
227 if (test_and_clear_bit(ASYNCB_INITIALIZED
, &port
->flags
)) {
229 * Turn off DTR and RTS early.
231 if (!tty
|| (tty
->termios
->c_cflag
& HUPCL
))
232 uart_clear_mctrl(uport
, TIOCM_DTR
| TIOCM_RTS
);
235 * clear delta_msr_wait queue to avoid mem leaks: we may free
236 * the irq here so the queue might never be woken up. Note
237 * that we won't end up waiting on delta_msr_wait again since
238 * any outstanding file descriptors should be pointing at
239 * hung_up_tty_fops now.
241 wake_up_interruptible(&port
->delta_msr_wait
);
244 * Free the IRQ and disable the port.
246 uport
->ops
->shutdown(uport
);
249 * Ensure that the IRQ handler isn't running on another CPU.
251 synchronize_irq(uport
->irq
);
255 * kill off our tasklet
257 tasklet_kill(&state
->tlet
);
260 * Free the transmit buffer page.
262 if (state
->xmit
.buf
) {
263 free_page((unsigned long)state
->xmit
.buf
);
264 state
->xmit
.buf
= NULL
;
269 * uart_update_timeout - update per-port FIFO timeout.
270 * @port: uart_port structure describing the port
271 * @cflag: termios cflag value
272 * @baud: speed of the port
274 * Set the port FIFO timeout value. The @cflag value should
275 * reflect the actual hardware settings.
278 uart_update_timeout(struct uart_port
*port
, unsigned int cflag
,
283 /* byte size and parity */
284 switch (cflag
& CSIZE
) {
305 * The total number of bits to be transmitted in the fifo.
307 bits
= bits
* port
->fifosize
;
310 * Figure the timeout to send the above number of bits.
311 * Add .02 seconds of slop
313 port
->timeout
= (HZ
* bits
) / baud
+ HZ
/50;
316 EXPORT_SYMBOL(uart_update_timeout
);
319 * uart_get_baud_rate - return baud rate for a particular port
320 * @port: uart_port structure describing the port in question.
321 * @termios: desired termios settings.
322 * @old: old termios (or NULL)
323 * @min: minimum acceptable baud rate
324 * @max: maximum acceptable baud rate
326 * Decode the termios structure into a numeric baud rate,
327 * taking account of the magic 38400 baud rate (with spd_*
328 * flags), and mapping the %B0 rate to 9600 baud.
330 * If the new baud rate is invalid, try the old termios setting.
331 * If it's still invalid, we try 9600 baud.
333 * Update the @termios structure to reflect the baud rate
334 * we're actually going to be using. Don't do this for the case
335 * where B0 is requested ("hang up").
338 uart_get_baud_rate(struct uart_port
*port
, struct ktermios
*termios
,
339 struct ktermios
*old
, unsigned int min
, unsigned int max
)
341 unsigned int try, baud
, altbaud
= 38400;
343 upf_t flags
= port
->flags
& UPF_SPD_MASK
;
345 if (flags
== UPF_SPD_HI
)
347 else if (flags
== UPF_SPD_VHI
)
349 else if (flags
== UPF_SPD_SHI
)
351 else if (flags
== UPF_SPD_WARP
)
354 for (try = 0; try < 2; try++) {
355 baud
= tty_termios_baud_rate(termios
);
358 * The spd_hi, spd_vhi, spd_shi, spd_warp kludge...
365 * Special case: B0 rate.
372 if (baud
>= min
&& baud
<= max
)
376 * Oops, the quotient was zero. Try again with
377 * the old baud rate if possible.
379 termios
->c_cflag
&= ~CBAUD
;
381 baud
= tty_termios_baud_rate(old
);
383 tty_termios_encode_baud_rate(termios
,
390 * As a last resort, if the range cannot be met then clip to
391 * the nearest chip supported rate.
395 tty_termios_encode_baud_rate(termios
,
398 tty_termios_encode_baud_rate(termios
,
402 /* Should never happen */
407 EXPORT_SYMBOL(uart_get_baud_rate
);
410 * uart_get_divisor - return uart clock divisor
411 * @port: uart_port structure describing the port.
412 * @baud: desired baud rate
414 * Calculate the uart clock divisor for the port.
417 uart_get_divisor(struct uart_port
*port
, unsigned int baud
)
422 * Old custom speed handling.
424 if (baud
== 38400 && (port
->flags
& UPF_SPD_MASK
) == UPF_SPD_CUST
)
425 quot
= port
->custom_divisor
;
427 quot
= (port
->uartclk
+ (8 * baud
)) / (16 * baud
);
432 EXPORT_SYMBOL(uart_get_divisor
);
434 /* FIXME: Consistent locking policy */
435 static void uart_change_speed(struct tty_struct
*tty
, struct uart_state
*state
,
436 struct ktermios
*old_termios
)
438 struct tty_port
*port
= &state
->port
;
439 struct uart_port
*uport
= state
->uart_port
;
440 struct ktermios
*termios
;
443 * If we have no tty, termios, or the port does not exist,
444 * then we can't set the parameters for this port.
446 if (!tty
|| !tty
->termios
|| uport
->type
== PORT_UNKNOWN
)
449 termios
= tty
->termios
;
452 * Set flags based on termios cflag
454 if (termios
->c_cflag
& CRTSCTS
)
455 set_bit(ASYNCB_CTS_FLOW
, &port
->flags
);
457 clear_bit(ASYNCB_CTS_FLOW
, &port
->flags
);
459 if (termios
->c_cflag
& CLOCAL
)
460 clear_bit(ASYNCB_CHECK_CD
, &port
->flags
);
462 set_bit(ASYNCB_CHECK_CD
, &port
->flags
);
464 uport
->ops
->set_termios(uport
, termios
, old_termios
);
467 static inline int __uart_put_char(struct uart_port
*port
,
468 struct circ_buf
*circ
, unsigned char c
)
476 spin_lock_irqsave(&port
->lock
, flags
);
477 if (uart_circ_chars_free(circ
) != 0) {
478 circ
->buf
[circ
->head
] = c
;
479 circ
->head
= (circ
->head
+ 1) & (UART_XMIT_SIZE
- 1);
482 spin_unlock_irqrestore(&port
->lock
, flags
);
486 static int uart_put_char(struct tty_struct
*tty
, unsigned char ch
)
488 struct uart_state
*state
= tty
->driver_data
;
490 return __uart_put_char(state
->uart_port
, &state
->xmit
, ch
);
493 static void uart_flush_chars(struct tty_struct
*tty
)
498 static int uart_write(struct tty_struct
*tty
,
499 const unsigned char *buf
, int count
)
501 struct uart_state
*state
= tty
->driver_data
;
502 struct uart_port
*port
;
503 struct circ_buf
*circ
;
508 * This means you called this function _after_ the port was
509 * closed. No cookie for you.
516 port
= state
->uart_port
;
522 spin_lock_irqsave(&port
->lock
, flags
);
524 c
= CIRC_SPACE_TO_END(circ
->head
, circ
->tail
, UART_XMIT_SIZE
);
529 memcpy(circ
->buf
+ circ
->head
, buf
, c
);
530 circ
->head
= (circ
->head
+ c
) & (UART_XMIT_SIZE
- 1);
535 spin_unlock_irqrestore(&port
->lock
, flags
);
541 static int uart_write_room(struct tty_struct
*tty
)
543 struct uart_state
*state
= tty
->driver_data
;
547 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
548 ret
= uart_circ_chars_free(&state
->xmit
);
549 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
553 static int uart_chars_in_buffer(struct tty_struct
*tty
)
555 struct uart_state
*state
= tty
->driver_data
;
559 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
560 ret
= uart_circ_chars_pending(&state
->xmit
);
561 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
565 static void uart_flush_buffer(struct tty_struct
*tty
)
567 struct uart_state
*state
= tty
->driver_data
;
568 struct uart_port
*port
;
572 * This means you called this function _after_ the port was
573 * closed. No cookie for you.
580 port
= state
->uart_port
;
581 pr_debug("uart_flush_buffer(%d) called\n", tty
->index
);
583 spin_lock_irqsave(&port
->lock
, flags
);
584 uart_circ_clear(&state
->xmit
);
585 if (port
->ops
->flush_buffer
)
586 port
->ops
->flush_buffer(port
);
587 spin_unlock_irqrestore(&port
->lock
, flags
);
592 * This function is used to send a high-priority XON/XOFF character to
595 static void uart_send_xchar(struct tty_struct
*tty
, char ch
)
597 struct uart_state
*state
= tty
->driver_data
;
598 struct uart_port
*port
= state
->uart_port
;
601 if (port
->ops
->send_xchar
)
602 port
->ops
->send_xchar(port
, ch
);
606 spin_lock_irqsave(&port
->lock
, flags
);
607 port
->ops
->start_tx(port
);
608 spin_unlock_irqrestore(&port
->lock
, flags
);
613 static void uart_throttle(struct tty_struct
*tty
)
615 struct uart_state
*state
= tty
->driver_data
;
618 uart_send_xchar(tty
, STOP_CHAR(tty
));
620 if (tty
->termios
->c_cflag
& CRTSCTS
)
621 uart_clear_mctrl(state
->uart_port
, TIOCM_RTS
);
624 static void uart_unthrottle(struct tty_struct
*tty
)
626 struct uart_state
*state
= tty
->driver_data
;
627 struct uart_port
*port
= state
->uart_port
;
633 uart_send_xchar(tty
, START_CHAR(tty
));
636 if (tty
->termios
->c_cflag
& CRTSCTS
)
637 uart_set_mctrl(port
, TIOCM_RTS
);
640 static int uart_get_info(struct uart_state
*state
,
641 struct serial_struct __user
*retinfo
)
643 struct uart_port
*uport
= state
->uart_port
;
644 struct tty_port
*port
= &state
->port
;
645 struct serial_struct tmp
;
647 memset(&tmp
, 0, sizeof(tmp
));
649 /* Ensure the state we copy is consistent and no hardware changes
651 mutex_lock(&port
->mutex
);
653 tmp
.type
= uport
->type
;
654 tmp
.line
= uport
->line
;
655 tmp
.port
= uport
->iobase
;
656 if (HIGH_BITS_OFFSET
)
657 tmp
.port_high
= (long) uport
->iobase
>> HIGH_BITS_OFFSET
;
658 tmp
.irq
= uport
->irq
;
659 tmp
.flags
= uport
->flags
;
660 tmp
.xmit_fifo_size
= uport
->fifosize
;
661 tmp
.baud_base
= uport
->uartclk
/ 16;
662 tmp
.close_delay
= port
->close_delay
/ 10;
663 tmp
.closing_wait
= port
->closing_wait
== ASYNC_CLOSING_WAIT_NONE
?
664 ASYNC_CLOSING_WAIT_NONE
:
665 port
->closing_wait
/ 10;
666 tmp
.custom_divisor
= uport
->custom_divisor
;
667 tmp
.hub6
= uport
->hub6
;
668 tmp
.io_type
= uport
->iotype
;
669 tmp
.iomem_reg_shift
= uport
->regshift
;
670 tmp
.iomem_base
= (void *)(unsigned long)uport
->mapbase
;
672 mutex_unlock(&port
->mutex
);
674 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
679 static int uart_set_info(struct tty_struct
*tty
, struct uart_state
*state
,
680 struct serial_struct __user
*newinfo
)
682 struct serial_struct new_serial
;
683 struct uart_port
*uport
= state
->uart_port
;
684 struct tty_port
*port
= &state
->port
;
685 unsigned long new_port
;
686 unsigned int change_irq
, change_port
, closing_wait
;
687 unsigned int old_custom_divisor
, close_delay
;
688 upf_t old_flags
, new_flags
;
691 if (copy_from_user(&new_serial
, newinfo
, sizeof(new_serial
)))
694 new_port
= new_serial
.port
;
695 if (HIGH_BITS_OFFSET
)
696 new_port
+= (unsigned long) new_serial
.port_high
<< HIGH_BITS_OFFSET
;
698 new_serial
.irq
= irq_canonicalize(new_serial
.irq
);
699 close_delay
= new_serial
.close_delay
* 10;
700 closing_wait
= new_serial
.closing_wait
== ASYNC_CLOSING_WAIT_NONE
?
701 ASYNC_CLOSING_WAIT_NONE
: new_serial
.closing_wait
* 10;
704 * This semaphore protects port->count. It is also
705 * very useful to prevent opens. Also, take the
706 * port configuration semaphore to make sure that a
707 * module insertion/removal doesn't change anything
710 mutex_lock(&port
->mutex
);
712 change_irq
= !(uport
->flags
& UPF_FIXED_PORT
)
713 && new_serial
.irq
!= uport
->irq
;
716 * Since changing the 'type' of the port changes its resource
717 * allocations, we should treat type changes the same as
720 change_port
= !(uport
->flags
& UPF_FIXED_PORT
)
721 && (new_port
!= uport
->iobase
||
722 (unsigned long)new_serial
.iomem_base
!= uport
->mapbase
||
723 new_serial
.hub6
!= uport
->hub6
||
724 new_serial
.io_type
!= uport
->iotype
||
725 new_serial
.iomem_reg_shift
!= uport
->regshift
||
726 new_serial
.type
!= uport
->type
);
728 old_flags
= uport
->flags
;
729 new_flags
= new_serial
.flags
;
730 old_custom_divisor
= uport
->custom_divisor
;
732 if (!capable(CAP_SYS_ADMIN
)) {
734 if (change_irq
|| change_port
||
735 (new_serial
.baud_base
!= uport
->uartclk
/ 16) ||
736 (close_delay
!= port
->close_delay
) ||
737 (closing_wait
!= port
->closing_wait
) ||
738 (new_serial
.xmit_fifo_size
&&
739 new_serial
.xmit_fifo_size
!= uport
->fifosize
) ||
740 (((new_flags
^ old_flags
) & ~UPF_USR_MASK
) != 0))
742 uport
->flags
= ((uport
->flags
& ~UPF_USR_MASK
) |
743 (new_flags
& UPF_USR_MASK
));
744 uport
->custom_divisor
= new_serial
.custom_divisor
;
749 * Ask the low level driver to verify the settings.
751 if (uport
->ops
->verify_port
)
752 retval
= uport
->ops
->verify_port(uport
, &new_serial
);
754 if ((new_serial
.irq
>= nr_irqs
) || (new_serial
.irq
< 0) ||
755 (new_serial
.baud_base
< 9600))
761 if (change_port
|| change_irq
) {
765 * Make sure that we are the sole user of this port.
767 if (tty_port_users(port
) > 1)
771 * We need to shutdown the serial port at the old
772 * port/type/irq combination.
774 uart_shutdown(tty
, state
);
778 unsigned long old_iobase
, old_mapbase
;
779 unsigned int old_type
, old_iotype
, old_hub6
, old_shift
;
781 old_iobase
= uport
->iobase
;
782 old_mapbase
= uport
->mapbase
;
783 old_type
= uport
->type
;
784 old_hub6
= uport
->hub6
;
785 old_iotype
= uport
->iotype
;
786 old_shift
= uport
->regshift
;
789 * Free and release old regions
791 if (old_type
!= PORT_UNKNOWN
)
792 uport
->ops
->release_port(uport
);
794 uport
->iobase
= new_port
;
795 uport
->type
= new_serial
.type
;
796 uport
->hub6
= new_serial
.hub6
;
797 uport
->iotype
= new_serial
.io_type
;
798 uport
->regshift
= new_serial
.iomem_reg_shift
;
799 uport
->mapbase
= (unsigned long)new_serial
.iomem_base
;
802 * Claim and map the new regions
804 if (uport
->type
!= PORT_UNKNOWN
) {
805 retval
= uport
->ops
->request_port(uport
);
807 /* Always success - Jean II */
812 * If we fail to request resources for the
813 * new port, try to restore the old settings.
815 if (retval
&& old_type
!= PORT_UNKNOWN
) {
816 uport
->iobase
= old_iobase
;
817 uport
->type
= old_type
;
818 uport
->hub6
= old_hub6
;
819 uport
->iotype
= old_iotype
;
820 uport
->regshift
= old_shift
;
821 uport
->mapbase
= old_mapbase
;
822 retval
= uport
->ops
->request_port(uport
);
824 * If we failed to restore the old settings,
828 uport
->type
= PORT_UNKNOWN
;
834 /* Added to return the correct error -Ram Gupta */
840 uport
->irq
= new_serial
.irq
;
841 if (!(uport
->flags
& UPF_FIXED_PORT
))
842 uport
->uartclk
= new_serial
.baud_base
* 16;
843 uport
->flags
= (uport
->flags
& ~UPF_CHANGE_MASK
) |
844 (new_flags
& UPF_CHANGE_MASK
);
845 uport
->custom_divisor
= new_serial
.custom_divisor
;
846 port
->close_delay
= close_delay
;
847 port
->closing_wait
= closing_wait
;
848 if (new_serial
.xmit_fifo_size
)
849 uport
->fifosize
= new_serial
.xmit_fifo_size
;
851 port
->tty
->low_latency
=
852 (uport
->flags
& UPF_LOW_LATENCY
) ? 1 : 0;
856 if (uport
->type
== PORT_UNKNOWN
)
858 if (port
->flags
& ASYNC_INITIALIZED
) {
859 if (((old_flags
^ uport
->flags
) & UPF_SPD_MASK
) ||
860 old_custom_divisor
!= uport
->custom_divisor
) {
862 * If they're setting up a custom divisor or speed,
863 * instead of clearing it, then bitch about it. No
864 * need to rate-limit; it's CAP_SYS_ADMIN only.
866 if (uport
->flags
& UPF_SPD_MASK
) {
869 "%s sets custom speed on %s. This "
870 "is deprecated.\n", current
->comm
,
871 tty_name(port
->tty
, buf
));
873 uart_change_speed(tty
, state
, NULL
);
876 retval
= uart_startup(tty
, state
, 1);
878 mutex_unlock(&port
->mutex
);
883 * uart_get_lsr_info - get line status register info
884 * @tty: tty associated with the UART
885 * @state: UART being queried
886 * @value: returned modem value
888 * Note: uart_ioctl protects us against hangups.
890 static int uart_get_lsr_info(struct tty_struct
*tty
,
891 struct uart_state
*state
, unsigned int __user
*value
)
893 struct uart_port
*uport
= state
->uart_port
;
896 result
= uport
->ops
->tx_empty(uport
);
899 * If we're about to load something into the transmit
900 * register, we'll pretend the transmitter isn't empty to
901 * avoid a race condition (depending on when the transmit
902 * interrupt happens).
905 ((uart_circ_chars_pending(&state
->xmit
) > 0) &&
906 !tty
->stopped
&& !tty
->hw_stopped
))
907 result
&= ~TIOCSER_TEMT
;
909 return put_user(result
, value
);
912 static int uart_tiocmget(struct tty_struct
*tty
)
914 struct uart_state
*state
= tty
->driver_data
;
915 struct tty_port
*port
= &state
->port
;
916 struct uart_port
*uport
= state
->uart_port
;
919 mutex_lock(&port
->mutex
);
920 if (!(tty
->flags
& (1 << TTY_IO_ERROR
))) {
921 result
= uport
->mctrl
;
922 spin_lock_irq(&uport
->lock
);
923 result
|= uport
->ops
->get_mctrl(uport
);
924 spin_unlock_irq(&uport
->lock
);
926 mutex_unlock(&port
->mutex
);
932 uart_tiocmset(struct tty_struct
*tty
, unsigned int set
, unsigned int clear
)
934 struct uart_state
*state
= tty
->driver_data
;
935 struct uart_port
*uport
= state
->uart_port
;
936 struct tty_port
*port
= &state
->port
;
939 mutex_lock(&port
->mutex
);
940 if (!(tty
->flags
& (1 << TTY_IO_ERROR
))) {
941 uart_update_mctrl(uport
, set
, clear
);
944 mutex_unlock(&port
->mutex
);
948 static int uart_break_ctl(struct tty_struct
*tty
, int break_state
)
950 struct uart_state
*state
= tty
->driver_data
;
951 struct tty_port
*port
= &state
->port
;
952 struct uart_port
*uport
= state
->uart_port
;
954 mutex_lock(&port
->mutex
);
956 if (uport
->type
!= PORT_UNKNOWN
)
957 uport
->ops
->break_ctl(uport
, break_state
);
959 mutex_unlock(&port
->mutex
);
963 static int uart_do_autoconfig(struct tty_struct
*tty
,struct uart_state
*state
)
965 struct uart_port
*uport
= state
->uart_port
;
966 struct tty_port
*port
= &state
->port
;
969 if (!capable(CAP_SYS_ADMIN
))
973 * Take the per-port semaphore. This prevents count from
974 * changing, and hence any extra opens of the port while
975 * we're auto-configuring.
977 if (mutex_lock_interruptible(&port
->mutex
))
981 if (tty_port_users(port
) == 1) {
982 uart_shutdown(tty
, state
);
985 * If we already have a port type configured,
986 * we must release its resources.
988 if (uport
->type
!= PORT_UNKNOWN
)
989 uport
->ops
->release_port(uport
);
991 flags
= UART_CONFIG_TYPE
;
992 if (uport
->flags
& UPF_AUTO_IRQ
)
993 flags
|= UART_CONFIG_IRQ
;
996 * This will claim the ports resources if
999 uport
->ops
->config_port(uport
, flags
);
1001 ret
= uart_startup(tty
, state
, 1);
1003 mutex_unlock(&port
->mutex
);
1008 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1009 * - mask passed in arg for lines of interest
1010 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1011 * Caller should use TIOCGICOUNT to see which one it was
1013 * FIXME: This wants extracting into a common all driver implementation
1014 * of TIOCMWAIT using tty_port.
1017 uart_wait_modem_status(struct uart_state
*state
, unsigned long arg
)
1019 struct uart_port
*uport
= state
->uart_port
;
1020 struct tty_port
*port
= &state
->port
;
1021 DECLARE_WAITQUEUE(wait
, current
);
1022 struct uart_icount cprev
, cnow
;
1026 * note the counters on entry
1028 spin_lock_irq(&uport
->lock
);
1029 memcpy(&cprev
, &uport
->icount
, sizeof(struct uart_icount
));
1032 * Force modem status interrupts on
1034 uport
->ops
->enable_ms(uport
);
1035 spin_unlock_irq(&uport
->lock
);
1037 add_wait_queue(&port
->delta_msr_wait
, &wait
);
1039 spin_lock_irq(&uport
->lock
);
1040 memcpy(&cnow
, &uport
->icount
, sizeof(struct uart_icount
));
1041 spin_unlock_irq(&uport
->lock
);
1043 set_current_state(TASK_INTERRUPTIBLE
);
1045 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1046 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1047 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1048 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
))) {
1055 /* see if a signal did it */
1056 if (signal_pending(current
)) {
1064 current
->state
= TASK_RUNNING
;
1065 remove_wait_queue(&port
->delta_msr_wait
, &wait
);
1071 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1072 * Return: write counters to the user passed counter struct
1073 * NB: both 1->0 and 0->1 transitions are counted except for
1074 * RI where only 0->1 is counted.
1076 static int uart_get_icount(struct tty_struct
*tty
,
1077 struct serial_icounter_struct
*icount
)
1079 struct uart_state
*state
= tty
->driver_data
;
1080 struct uart_icount cnow
;
1081 struct uart_port
*uport
= state
->uart_port
;
1083 spin_lock_irq(&uport
->lock
);
1084 memcpy(&cnow
, &uport
->icount
, sizeof(struct uart_icount
));
1085 spin_unlock_irq(&uport
->lock
);
1087 icount
->cts
= cnow
.cts
;
1088 icount
->dsr
= cnow
.dsr
;
1089 icount
->rng
= cnow
.rng
;
1090 icount
->dcd
= cnow
.dcd
;
1091 icount
->rx
= cnow
.rx
;
1092 icount
->tx
= cnow
.tx
;
1093 icount
->frame
= cnow
.frame
;
1094 icount
->overrun
= cnow
.overrun
;
1095 icount
->parity
= cnow
.parity
;
1096 icount
->brk
= cnow
.brk
;
1097 icount
->buf_overrun
= cnow
.buf_overrun
;
1103 * Called via sys_ioctl. We can use spin_lock_irq() here.
1106 uart_ioctl(struct tty_struct
*tty
, unsigned int cmd
,
1109 struct uart_state
*state
= tty
->driver_data
;
1110 struct tty_port
*port
= &state
->port
;
1111 void __user
*uarg
= (void __user
*)arg
;
1112 int ret
= -ENOIOCTLCMD
;
1116 * These ioctls don't rely on the hardware to be present.
1120 ret
= uart_get_info(state
, uarg
);
1124 ret
= uart_set_info(tty
, state
, uarg
);
1128 ret
= uart_do_autoconfig(tty
, state
);
1131 case TIOCSERGWILD
: /* obsolete */
1132 case TIOCSERSWILD
: /* obsolete */
1137 if (ret
!= -ENOIOCTLCMD
)
1140 if (tty
->flags
& (1 << TTY_IO_ERROR
)) {
1146 * The following should only be used when hardware is present.
1150 ret
= uart_wait_modem_status(state
, arg
);
1154 if (ret
!= -ENOIOCTLCMD
)
1157 mutex_lock(&port
->mutex
);
1159 if (tty
->flags
& (1 << TTY_IO_ERROR
)) {
1165 * All these rely on hardware being present and need to be
1166 * protected against the tty being hung up.
1169 case TIOCSERGETLSR
: /* Get line status register */
1170 ret
= uart_get_lsr_info(tty
, state
, uarg
);
1174 struct uart_port
*uport
= state
->uart_port
;
1175 if (uport
->ops
->ioctl
)
1176 ret
= uport
->ops
->ioctl(uport
, cmd
, arg
);
1181 mutex_unlock(&port
->mutex
);
1186 static void uart_set_ldisc(struct tty_struct
*tty
)
1188 struct uart_state
*state
= tty
->driver_data
;
1189 struct uart_port
*uport
= state
->uart_port
;
1191 if (uport
->ops
->set_ldisc
)
1192 uport
->ops
->set_ldisc(uport
, tty
->termios
->c_line
);
1195 static void uart_set_termios(struct tty_struct
*tty
,
1196 struct ktermios
*old_termios
)
1198 struct uart_state
*state
= tty
->driver_data
;
1199 unsigned long flags
;
1200 unsigned int cflag
= tty
->termios
->c_cflag
;
1204 * These are the bits that are used to setup various
1205 * flags in the low level driver. We can ignore the Bfoo
1206 * bits in c_cflag; c_[io]speed will always be set
1207 * appropriately by set_termios() in tty_ioctl.c
1209 #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1210 if ((cflag
^ old_termios
->c_cflag
) == 0 &&
1211 tty
->termios
->c_ospeed
== old_termios
->c_ospeed
&&
1212 tty
->termios
->c_ispeed
== old_termios
->c_ispeed
&&
1213 RELEVANT_IFLAG(tty
->termios
->c_iflag
^ old_termios
->c_iflag
) == 0) {
1217 uart_change_speed(tty
, state
, old_termios
);
1219 /* Handle transition to B0 status */
1220 if ((old_termios
->c_cflag
& CBAUD
) && !(cflag
& CBAUD
))
1221 uart_clear_mctrl(state
->uart_port
, TIOCM_RTS
| TIOCM_DTR
);
1222 /* Handle transition away from B0 status */
1223 else if (!(old_termios
->c_cflag
& CBAUD
) && (cflag
& CBAUD
)) {
1224 unsigned int mask
= TIOCM_DTR
;
1225 if (!(cflag
& CRTSCTS
) ||
1226 !test_bit(TTY_THROTTLED
, &tty
->flags
))
1228 uart_set_mctrl(state
->uart_port
, mask
);
1231 /* Handle turning off CRTSCTS */
1232 if ((old_termios
->c_cflag
& CRTSCTS
) && !(cflag
& CRTSCTS
)) {
1233 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
1234 tty
->hw_stopped
= 0;
1236 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
1238 /* Handle turning on CRTSCTS */
1239 else if (!(old_termios
->c_cflag
& CRTSCTS
) && (cflag
& CRTSCTS
)) {
1240 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
1241 if (!(state
->uart_port
->ops
->get_mctrl(state
->uart_port
) & TIOCM_CTS
)) {
1242 tty
->hw_stopped
= 1;
1243 state
->uart_port
->ops
->stop_tx(state
->uart_port
);
1245 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
1249 * No need to wake up processes in open wait, since they
1250 * sample the CLOCAL flag once, and don't recheck it.
1251 * XXX It's not clear whether the current behavior is correct
1252 * or not. Hence, this may change.....
1254 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1255 (tty
->termios
->c_cflag
& CLOCAL
))
1256 wake_up_interruptible(&state
->uart_port
.open_wait
);
1261 * In 2.4.5, calls to this will be serialized via the BKL in
1262 * linux/drivers/char/tty_io.c:tty_release()
1263 * linux/drivers/char/tty_io.c:do_tty_handup()
1265 static void uart_close(struct tty_struct
*tty
, struct file
*filp
)
1267 struct uart_state
*state
= tty
->driver_data
;
1268 struct tty_port
*port
;
1269 struct uart_port
*uport
;
1270 unsigned long flags
;
1272 BUG_ON(!tty_locked());
1277 uport
= state
->uart_port
;
1278 port
= &state
->port
;
1280 pr_debug("uart_close(%d) called\n", uport
->line
);
1282 mutex_lock(&port
->mutex
);
1283 spin_lock_irqsave(&port
->lock
, flags
);
1285 if (tty_hung_up_p(filp
)) {
1286 spin_unlock_irqrestore(&port
->lock
, flags
);
1290 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1292 * Uh, oh. tty->count is 1, which means that the tty
1293 * structure will be freed. port->count should always
1294 * be one in these conditions. If it's greater than
1295 * one, we've got real problems, since it means the
1296 * serial port won't be shutdown.
1298 printk(KERN_ERR
"uart_close: bad serial port count; tty->count is 1, "
1299 "port->count is %d\n", port
->count
);
1302 if (--port
->count
< 0) {
1303 printk(KERN_ERR
"uart_close: bad serial port count for %s: %d\n",
1304 tty
->name
, port
->count
);
1308 spin_unlock_irqrestore(&port
->lock
, flags
);
1313 * Now we wait for the transmit buffer to clear; and we notify
1314 * the line discipline to only process XON/XOFF characters by
1315 * setting tty->closing.
1318 spin_unlock_irqrestore(&port
->lock
, flags
);
1320 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
) {
1322 * hack: open-coded tty_wait_until_sent to avoid
1323 * recursive tty_lock
1325 long timeout
= msecs_to_jiffies(port
->closing_wait
);
1326 if (wait_event_interruptible_timeout(tty
->write_wait
,
1327 !tty_chars_in_buffer(tty
), timeout
) >= 0)
1328 __uart_wait_until_sent(uport
, timeout
);
1332 * At this point, we stop accepting input. To do this, we
1333 * disable the receive line status interrupts.
1335 if (port
->flags
& ASYNC_INITIALIZED
) {
1336 unsigned long flags
;
1337 spin_lock_irqsave(&uport
->lock
, flags
);
1338 uport
->ops
->stop_rx(uport
);
1339 spin_unlock_irqrestore(&uport
->lock
, flags
);
1341 * Before we drop DTR, make sure the UART transmitter
1342 * has completely drained; this is especially
1343 * important if there is a transmit FIFO!
1345 __uart_wait_until_sent(uport
, uport
->timeout
);
1348 uart_shutdown(tty
, state
);
1349 uart_flush_buffer(tty
);
1351 tty_ldisc_flush(tty
);
1353 tty_port_tty_set(port
, NULL
);
1354 spin_lock_irqsave(&port
->lock
, flags
);
1357 if (port
->blocked_open
) {
1358 spin_unlock_irqrestore(&port
->lock
, flags
);
1359 if (port
->close_delay
)
1360 msleep_interruptible(port
->close_delay
);
1361 spin_lock_irqsave(&port
->lock
, flags
);
1362 } else if (!uart_console(uport
)) {
1363 spin_unlock_irqrestore(&port
->lock
, flags
);
1364 uart_change_pm(state
, 3);
1365 spin_lock_irqsave(&port
->lock
, flags
);
1369 * Wake up anyone trying to open this port.
1371 clear_bit(ASYNCB_NORMAL_ACTIVE
, &port
->flags
);
1372 spin_unlock_irqrestore(&port
->lock
, flags
);
1373 wake_up_interruptible(&port
->open_wait
);
1376 mutex_unlock(&port
->mutex
);
1379 static void __uart_wait_until_sent(struct uart_port
*port
, int timeout
)
1381 unsigned long char_time
, expire
;
1383 if (port
->type
== PORT_UNKNOWN
|| port
->fifosize
== 0)
1387 * Set the check interval to be 1/5 of the estimated time to
1388 * send a single character, and make it at least 1. The check
1389 * interval should also be less than the timeout.
1391 * Note: we have to use pretty tight timings here to satisfy
1394 char_time
= (port
->timeout
- HZ
/50) / port
->fifosize
;
1395 char_time
= char_time
/ 5;
1398 if (timeout
&& timeout
< char_time
)
1399 char_time
= timeout
;
1402 * If the transmitter hasn't cleared in twice the approximate
1403 * amount of time to send the entire FIFO, it probably won't
1404 * ever clear. This assumes the UART isn't doing flow
1405 * control, which is currently the case. Hence, if it ever
1406 * takes longer than port->timeout, this is probably due to a
1407 * UART bug of some kind. So, we clamp the timeout parameter at
1410 if (timeout
== 0 || timeout
> 2 * port
->timeout
)
1411 timeout
= 2 * port
->timeout
;
1413 expire
= jiffies
+ timeout
;
1415 pr_debug("uart_wait_until_sent(%d), jiffies=%lu, expire=%lu...\n",
1416 port
->line
, jiffies
, expire
);
1419 * Check whether the transmitter is empty every 'char_time'.
1420 * 'timeout' / 'expire' give us the maximum amount of time
1423 while (!port
->ops
->tx_empty(port
)) {
1424 msleep_interruptible(jiffies_to_msecs(char_time
));
1425 if (signal_pending(current
))
1427 if (time_after(jiffies
, expire
))
1430 set_current_state(TASK_RUNNING
); /* might not be needed */
1433 static void uart_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1435 struct uart_state
*state
= tty
->driver_data
;
1436 struct uart_port
*port
= state
->uart_port
;
1439 __uart_wait_until_sent(port
, timeout
);
1444 * This is called with the BKL held in
1445 * linux/drivers/char/tty_io.c:do_tty_hangup()
1446 * We're called from the eventd thread, so we can sleep for
1447 * a _short_ time only.
1449 static void uart_hangup(struct tty_struct
*tty
)
1451 struct uart_state
*state
= tty
->driver_data
;
1452 struct tty_port
*port
= &state
->port
;
1453 unsigned long flags
;
1455 BUG_ON(!tty_locked());
1456 pr_debug("uart_hangup(%d)\n", state
->uart_port
->line
);
1458 mutex_lock(&port
->mutex
);
1459 if (port
->flags
& ASYNC_NORMAL_ACTIVE
) {
1460 uart_flush_buffer(tty
);
1461 uart_shutdown(tty
, state
);
1462 spin_lock_irqsave(&port
->lock
, flags
);
1464 clear_bit(ASYNCB_NORMAL_ACTIVE
, &port
->flags
);
1465 spin_unlock_irqrestore(&port
->lock
, flags
);
1466 tty_port_tty_set(port
, NULL
);
1467 wake_up_interruptible(&port
->open_wait
);
1468 wake_up_interruptible(&port
->delta_msr_wait
);
1470 mutex_unlock(&port
->mutex
);
1474 * uart_update_termios - update the terminal hw settings
1475 * @tty: tty associated with UART
1476 * @state: UART to update
1478 * Copy across the serial console cflag setting into the termios settings
1479 * for the initial open of the port. This allows continuity between the
1480 * kernel settings, and the settings init adopts when it opens the port
1481 * for the first time.
1483 static void uart_update_termios(struct tty_struct
*tty
,
1484 struct uart_state
*state
)
1486 struct uart_port
*port
= state
->uart_port
;
1489 * If the device failed to grab its irq resources,
1490 * or some other error occurred, don't try to talk
1491 * to the port hardware.
1493 if (!(tty
->flags
& (1 << TTY_IO_ERROR
))) {
1495 * And finally enable the RTS and DTR signals.
1497 if (tty
->termios
->c_cflag
& CBAUD
)
1498 uart_set_mctrl(port
, TIOCM_DTR
| TIOCM_RTS
);
1502 static int uart_carrier_raised(struct tty_port
*port
)
1504 struct uart_state
*state
= container_of(port
, struct uart_state
, port
);
1505 struct uart_port
*uport
= state
->uart_port
;
1507 spin_lock_irq(&uport
->lock
);
1508 uport
->ops
->enable_ms(uport
);
1509 mctrl
= uport
->ops
->get_mctrl(uport
);
1510 spin_unlock_irq(&uport
->lock
);
1511 if (mctrl
& TIOCM_CAR
)
1516 static void uart_dtr_rts(struct tty_port
*port
, int onoff
)
1518 struct uart_state
*state
= container_of(port
, struct uart_state
, port
);
1519 struct uart_port
*uport
= state
->uart_port
;
1522 uart_set_mctrl(uport
, TIOCM_DTR
| TIOCM_RTS
);
1525 * If this is the first open to succeed,
1526 * adjust things to suit.
1528 if (!test_and_set_bit(ASYNCB_NORMAL_ACTIVE
, &port
->flags
))
1529 uart_update_termios(port
->tty
, state
);
1532 uart_clear_mctrl(uport
, TIOCM_DTR
| TIOCM_RTS
);
1535 static struct uart_state
*uart_get(struct uart_driver
*drv
, int line
)
1537 struct uart_state
*state
;
1538 struct tty_port
*port
;
1541 state
= drv
->state
+ line
;
1542 port
= &state
->port
;
1543 if (mutex_lock_interruptible(&port
->mutex
)) {
1549 if (!state
->uart_port
|| state
->uart_port
->flags
& UPF_DEAD
) {
1557 mutex_unlock(&port
->mutex
);
1559 return ERR_PTR(ret
);
1563 * calls to uart_open are serialised by the BKL in
1564 * fs/char_dev.c:chrdev_open()
1565 * Note that if this fails, then uart_close() _will_ be called.
1567 * In time, we want to scrap the "opening nonpresent ports"
1568 * behaviour and implement an alternative way for setserial
1569 * to set base addresses/ports/types. This will allow us to
1570 * get rid of a certain amount of extra tests.
1572 static int uart_open(struct tty_struct
*tty
, struct file
*filp
)
1574 struct uart_driver
*drv
= (struct uart_driver
*)tty
->driver
->driver_state
;
1575 struct uart_state
*state
;
1576 struct tty_port
*port
;
1577 int retval
, line
= tty
->index
;
1579 BUG_ON(!tty_locked());
1580 pr_debug("uart_open(%d) called\n", line
);
1583 * tty->driver->num won't change, so we won't fail here with
1584 * tty->driver_data set to something non-NULL (and therefore
1585 * we won't get caught by uart_close()).
1588 if (line
>= tty
->driver
->num
)
1592 * We take the semaphore inside uart_get to guarantee that we won't
1593 * be re-entered while allocating the state structure, or while we
1594 * request any IRQs that the driver may need. This also has the nice
1595 * side-effect that it delays the action of uart_hangup, so we can
1596 * guarantee that state->port.tty will always contain something
1599 state
= uart_get(drv
, line
);
1600 if (IS_ERR(state
)) {
1601 retval
= PTR_ERR(state
);
1604 port
= &state
->port
;
1607 * Once we set tty->driver_data here, we are guaranteed that
1608 * uart_close() will decrement the driver module use count.
1609 * Any failures from here onwards should not touch the count.
1611 tty
->driver_data
= state
;
1612 state
->uart_port
->state
= state
;
1613 tty
->low_latency
= (state
->uart_port
->flags
& UPF_LOW_LATENCY
) ? 1 : 0;
1615 tty_port_tty_set(port
, tty
);
1618 * If the port is in the middle of closing, bail out now.
1620 if (tty_hung_up_p(filp
)) {
1623 mutex_unlock(&port
->mutex
);
1628 * Make sure the device is in D0 state.
1630 if (port
->count
== 1)
1631 uart_change_pm(state
, 0);
1634 * Start up the serial port.
1636 retval
= uart_startup(tty
, state
, 0);
1639 * If we succeeded, wait until the port is ready.
1641 mutex_unlock(&port
->mutex
);
1643 retval
= tty_port_block_til_ready(port
, tty
, filp
);
1649 static const char *uart_type(struct uart_port
*port
)
1651 const char *str
= NULL
;
1653 if (port
->ops
->type
)
1654 str
= port
->ops
->type(port
);
1662 #ifdef CONFIG_PROC_FS
1664 static void uart_line_info(struct seq_file
*m
, struct uart_driver
*drv
, int i
)
1666 struct uart_state
*state
= drv
->state
+ i
;
1667 struct tty_port
*port
= &state
->port
;
1669 struct uart_port
*uport
= state
->uart_port
;
1671 unsigned int status
;
1677 mmio
= uport
->iotype
>= UPIO_MEM
;
1678 seq_printf(m
, "%d: uart:%s %s%08llX irq:%d",
1679 uport
->line
, uart_type(uport
),
1680 mmio
? "mmio:0x" : "port:",
1681 mmio
? (unsigned long long)uport
->mapbase
1682 : (unsigned long long)uport
->iobase
,
1685 if (uport
->type
== PORT_UNKNOWN
) {
1690 if (capable(CAP_SYS_ADMIN
)) {
1691 mutex_lock(&port
->mutex
);
1692 pm_state
= state
->pm_state
;
1694 uart_change_pm(state
, 0);
1695 spin_lock_irq(&uport
->lock
);
1696 status
= uport
->ops
->get_mctrl(uport
);
1697 spin_unlock_irq(&uport
->lock
);
1699 uart_change_pm(state
, pm_state
);
1700 mutex_unlock(&port
->mutex
);
1702 seq_printf(m
, " tx:%d rx:%d",
1703 uport
->icount
.tx
, uport
->icount
.rx
);
1704 if (uport
->icount
.frame
)
1705 seq_printf(m
, " fe:%d",
1706 uport
->icount
.frame
);
1707 if (uport
->icount
.parity
)
1708 seq_printf(m
, " pe:%d",
1709 uport
->icount
.parity
);
1710 if (uport
->icount
.brk
)
1711 seq_printf(m
, " brk:%d",
1713 if (uport
->icount
.overrun
)
1714 seq_printf(m
, " oe:%d",
1715 uport
->icount
.overrun
);
1717 #define INFOBIT(bit, str) \
1718 if (uport->mctrl & (bit)) \
1719 strncat(stat_buf, (str), sizeof(stat_buf) - \
1720 strlen(stat_buf) - 2)
1721 #define STATBIT(bit, str) \
1722 if (status & (bit)) \
1723 strncat(stat_buf, (str), sizeof(stat_buf) - \
1724 strlen(stat_buf) - 2)
1728 INFOBIT(TIOCM_RTS
, "|RTS");
1729 STATBIT(TIOCM_CTS
, "|CTS");
1730 INFOBIT(TIOCM_DTR
, "|DTR");
1731 STATBIT(TIOCM_DSR
, "|DSR");
1732 STATBIT(TIOCM_CAR
, "|CD");
1733 STATBIT(TIOCM_RNG
, "|RI");
1737 seq_puts(m
, stat_buf
);
1744 static int uart_proc_show(struct seq_file
*m
, void *v
)
1746 struct tty_driver
*ttydrv
= m
->private;
1747 struct uart_driver
*drv
= ttydrv
->driver_state
;
1750 seq_printf(m
, "serinfo:1.0 driver%s%s revision:%s\n",
1752 for (i
= 0; i
< drv
->nr
; i
++)
1753 uart_line_info(m
, drv
, i
);
1757 static int uart_proc_open(struct inode
*inode
, struct file
*file
)
1759 return single_open(file
, uart_proc_show
, PDE(inode
)->data
);
1762 static const struct file_operations uart_proc_fops
= {
1763 .owner
= THIS_MODULE
,
1764 .open
= uart_proc_open
,
1766 .llseek
= seq_lseek
,
1767 .release
= single_release
,
1771 #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
1773 * uart_console_write - write a console message to a serial port
1774 * @port: the port to write the message
1775 * @s: array of characters
1776 * @count: number of characters in string to write
1777 * @write: function to write character to port
1779 void uart_console_write(struct uart_port
*port
, const char *s
,
1781 void (*putchar
)(struct uart_port
*, int))
1785 for (i
= 0; i
< count
; i
++, s
++) {
1787 putchar(port
, '\r');
1791 EXPORT_SYMBOL_GPL(uart_console_write
);
1794 * Check whether an invalid uart number has been specified, and
1795 * if so, search for the first available port that does have
1798 struct uart_port
* __init
1799 uart_get_console(struct uart_port
*ports
, int nr
, struct console
*co
)
1801 int idx
= co
->index
;
1803 if (idx
< 0 || idx
>= nr
|| (ports
[idx
].iobase
== 0 &&
1804 ports
[idx
].membase
== NULL
))
1805 for (idx
= 0; idx
< nr
; idx
++)
1806 if (ports
[idx
].iobase
!= 0 ||
1807 ports
[idx
].membase
!= NULL
)
1816 * uart_parse_options - Parse serial port baud/parity/bits/flow contro.
1817 * @options: pointer to option string
1818 * @baud: pointer to an 'int' variable for the baud rate.
1819 * @parity: pointer to an 'int' variable for the parity.
1820 * @bits: pointer to an 'int' variable for the number of data bits.
1821 * @flow: pointer to an 'int' variable for the flow control character.
1823 * uart_parse_options decodes a string containing the serial console
1824 * options. The format of the string is <baud><parity><bits><flow>,
1828 uart_parse_options(char *options
, int *baud
, int *parity
, int *bits
, int *flow
)
1832 *baud
= simple_strtoul(s
, NULL
, 10);
1833 while (*s
>= '0' && *s
<= '9')
1842 EXPORT_SYMBOL_GPL(uart_parse_options
);
1849 static const struct baud_rates baud_rates
[] = {
1850 { 921600, B921600
},
1851 { 460800, B460800
},
1852 { 230400, B230400
},
1853 { 115200, B115200
},
1865 * uart_set_options - setup the serial console parameters
1866 * @port: pointer to the serial ports uart_port structure
1867 * @co: console pointer
1869 * @parity: parity character - 'n' (none), 'o' (odd), 'e' (even)
1870 * @bits: number of data bits
1871 * @flow: flow control character - 'r' (rts)
1874 uart_set_options(struct uart_port
*port
, struct console
*co
,
1875 int baud
, int parity
, int bits
, int flow
)
1877 struct ktermios termios
;
1878 static struct ktermios dummy
;
1882 * Ensure that the serial console lock is initialised
1885 spin_lock_init(&port
->lock
);
1886 lockdep_set_class(&port
->lock
, &port_lock_key
);
1888 memset(&termios
, 0, sizeof(struct ktermios
));
1890 termios
.c_cflag
= CREAD
| HUPCL
| CLOCAL
;
1893 * Construct a cflag setting.
1895 for (i
= 0; baud_rates
[i
].rate
; i
++)
1896 if (baud_rates
[i
].rate
<= baud
)
1899 termios
.c_cflag
|= baud_rates
[i
].cflag
;
1902 termios
.c_cflag
|= CS7
;
1904 termios
.c_cflag
|= CS8
;
1908 termios
.c_cflag
|= PARODD
;
1911 termios
.c_cflag
|= PARENB
;
1916 termios
.c_cflag
|= CRTSCTS
;
1919 * some uarts on other side don't support no flow control.
1920 * So we set * DTR in host uart to make them happy
1922 port
->mctrl
|= TIOCM_DTR
;
1924 port
->ops
->set_termios(port
, &termios
, &dummy
);
1926 * Allow the setting of the UART parameters with a NULL console
1930 co
->cflag
= termios
.c_cflag
;
1934 EXPORT_SYMBOL_GPL(uart_set_options
);
1935 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
1937 static void uart_change_pm(struct uart_state
*state
, int pm_state
)
1939 struct uart_port
*port
= state
->uart_port
;
1941 if (state
->pm_state
!= pm_state
) {
1943 port
->ops
->pm(port
, pm_state
, state
->pm_state
);
1944 state
->pm_state
= pm_state
;
1949 struct uart_port
*port
;
1950 struct uart_driver
*driver
;
1953 static int serial_match_port(struct device
*dev
, void *data
)
1955 struct uart_match
*match
= data
;
1956 struct tty_driver
*tty_drv
= match
->driver
->tty_driver
;
1957 dev_t devt
= MKDEV(tty_drv
->major
, tty_drv
->minor_start
) +
1960 return dev
->devt
== devt
; /* Actually, only one tty per port */
1963 int uart_suspend_port(struct uart_driver
*drv
, struct uart_port
*uport
)
1965 struct uart_state
*state
= drv
->state
+ uport
->line
;
1966 struct tty_port
*port
= &state
->port
;
1967 struct device
*tty_dev
;
1968 struct uart_match match
= {uport
, drv
};
1970 mutex_lock(&port
->mutex
);
1972 tty_dev
= device_find_child(uport
->dev
, &match
, serial_match_port
);
1973 if (device_may_wakeup(tty_dev
)) {
1974 if (!enable_irq_wake(uport
->irq
))
1975 uport
->irq_wake
= 1;
1976 put_device(tty_dev
);
1977 mutex_unlock(&port
->mutex
);
1980 if (console_suspend_enabled
|| !uart_console(uport
))
1981 uport
->suspended
= 1;
1983 if (port
->flags
& ASYNC_INITIALIZED
) {
1984 const struct uart_ops
*ops
= uport
->ops
;
1987 if (console_suspend_enabled
|| !uart_console(uport
)) {
1988 set_bit(ASYNCB_SUSPENDED
, &port
->flags
);
1989 clear_bit(ASYNCB_INITIALIZED
, &port
->flags
);
1991 spin_lock_irq(&uport
->lock
);
1992 ops
->stop_tx(uport
);
1993 ops
->set_mctrl(uport
, 0);
1994 ops
->stop_rx(uport
);
1995 spin_unlock_irq(&uport
->lock
);
1999 * Wait for the transmitter to empty.
2001 for (tries
= 3; !ops
->tx_empty(uport
) && tries
; tries
--)
2004 printk(KERN_ERR
"%s%s%s%d: Unable to drain "
2006 uport
->dev
? dev_name(uport
->dev
) : "",
2007 uport
->dev
? ": " : "",
2009 drv
->tty_driver
->name_base
+ uport
->line
);
2011 if (console_suspend_enabled
|| !uart_console(uport
))
2012 ops
->shutdown(uport
);
2016 * Disable the console device before suspending.
2018 if (console_suspend_enabled
&& uart_console(uport
))
2019 console_stop(uport
->cons
);
2021 if (console_suspend_enabled
|| !uart_console(uport
))
2022 uart_change_pm(state
, 3);
2024 mutex_unlock(&port
->mutex
);
2029 int uart_resume_port(struct uart_driver
*drv
, struct uart_port
*uport
)
2031 struct uart_state
*state
= drv
->state
+ uport
->line
;
2032 struct tty_port
*port
= &state
->port
;
2033 struct device
*tty_dev
;
2034 struct uart_match match
= {uport
, drv
};
2035 struct ktermios termios
;
2037 mutex_lock(&port
->mutex
);
2039 tty_dev
= device_find_child(uport
->dev
, &match
, serial_match_port
);
2040 if (!uport
->suspended
&& device_may_wakeup(tty_dev
)) {
2041 if (uport
->irq_wake
) {
2042 disable_irq_wake(uport
->irq
);
2043 uport
->irq_wake
= 0;
2045 mutex_unlock(&port
->mutex
);
2048 uport
->suspended
= 0;
2051 * Re-enable the console device after suspending.
2053 if (uart_console(uport
)) {
2055 * First try to use the console cflag setting.
2057 memset(&termios
, 0, sizeof(struct ktermios
));
2058 termios
.c_cflag
= uport
->cons
->cflag
;
2061 * If that's unset, use the tty termios setting.
2063 if (port
->tty
&& port
->tty
->termios
&& termios
.c_cflag
== 0)
2064 termios
= *(port
->tty
->termios
);
2066 uport
->ops
->set_termios(uport
, &termios
, NULL
);
2067 if (console_suspend_enabled
)
2068 console_start(uport
->cons
);
2071 if (port
->flags
& ASYNC_SUSPENDED
) {
2072 const struct uart_ops
*ops
= uport
->ops
;
2075 uart_change_pm(state
, 0);
2076 spin_lock_irq(&uport
->lock
);
2077 ops
->set_mctrl(uport
, 0);
2078 spin_unlock_irq(&uport
->lock
);
2079 if (console_suspend_enabled
|| !uart_console(uport
)) {
2080 /* Protected by port mutex for now */
2081 struct tty_struct
*tty
= port
->tty
;
2082 ret
= ops
->startup(uport
);
2085 uart_change_speed(tty
, state
, NULL
);
2086 spin_lock_irq(&uport
->lock
);
2087 ops
->set_mctrl(uport
, uport
->mctrl
);
2088 ops
->start_tx(uport
);
2089 spin_unlock_irq(&uport
->lock
);
2090 set_bit(ASYNCB_INITIALIZED
, &port
->flags
);
2093 * Failed to resume - maybe hardware went away?
2094 * Clear the "initialized" flag so we won't try
2095 * to call the low level drivers shutdown method.
2097 uart_shutdown(tty
, state
);
2101 clear_bit(ASYNCB_SUSPENDED
, &port
->flags
);
2104 mutex_unlock(&port
->mutex
);
2110 uart_report_port(struct uart_driver
*drv
, struct uart_port
*port
)
2114 switch (port
->iotype
) {
2116 snprintf(address
, sizeof(address
), "I/O 0x%lx", port
->iobase
);
2119 snprintf(address
, sizeof(address
),
2120 "I/O 0x%lx offset 0x%x", port
->iobase
, port
->hub6
);
2128 snprintf(address
, sizeof(address
),
2129 "MMIO 0x%llx", (unsigned long long)port
->mapbase
);
2132 strlcpy(address
, "*unknown*", sizeof(address
));
2136 printk(KERN_INFO
"%s%s%s%d at %s (irq = %d) is a %s\n",
2137 port
->dev
? dev_name(port
->dev
) : "",
2138 port
->dev
? ": " : "",
2140 drv
->tty_driver
->name_base
+ port
->line
,
2141 address
, port
->irq
, uart_type(port
));
2145 uart_configure_port(struct uart_driver
*drv
, struct uart_state
*state
,
2146 struct uart_port
*port
)
2151 * If there isn't a port here, don't do anything further.
2153 if (!port
->iobase
&& !port
->mapbase
&& !port
->membase
)
2157 * Now do the auto configuration stuff. Note that config_port
2158 * is expected to claim the resources and map the port for us.
2161 if (port
->flags
& UPF_AUTO_IRQ
)
2162 flags
|= UART_CONFIG_IRQ
;
2163 if (port
->flags
& UPF_BOOT_AUTOCONF
) {
2164 if (!(port
->flags
& UPF_FIXED_TYPE
)) {
2165 port
->type
= PORT_UNKNOWN
;
2166 flags
|= UART_CONFIG_TYPE
;
2168 port
->ops
->config_port(port
, flags
);
2171 if (port
->type
!= PORT_UNKNOWN
) {
2172 unsigned long flags
;
2174 uart_report_port(drv
, port
);
2176 /* Power up port for set_mctrl() */
2177 uart_change_pm(state
, 0);
2180 * Ensure that the modem control lines are de-activated.
2181 * keep the DTR setting that is set in uart_set_options()
2182 * We probably don't need a spinlock around this, but
2184 spin_lock_irqsave(&port
->lock
, flags
);
2185 port
->ops
->set_mctrl(port
, port
->mctrl
& TIOCM_DTR
);
2186 spin_unlock_irqrestore(&port
->lock
, flags
);
2189 * If this driver supports console, and it hasn't been
2190 * successfully registered yet, try to re-register it.
2191 * It may be that the port was not available.
2193 if (port
->cons
&& !(port
->cons
->flags
& CON_ENABLED
))
2194 register_console(port
->cons
);
2197 * Power down all ports by default, except the
2198 * console if we have one.
2200 if (!uart_console(port
))
2201 uart_change_pm(state
, 3);
2205 #ifdef CONFIG_CONSOLE_POLL
2207 static int uart_poll_init(struct tty_driver
*driver
, int line
, char *options
)
2209 struct uart_driver
*drv
= driver
->driver_state
;
2210 struct uart_state
*state
= drv
->state
+ line
;
2211 struct uart_port
*port
;
2217 if (!state
|| !state
->uart_port
)
2220 port
= state
->uart_port
;
2221 if (!(port
->ops
->poll_get_char
&& port
->ops
->poll_put_char
))
2225 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
2226 return uart_set_options(port
, NULL
, baud
, parity
, bits
, flow
);
2232 static int uart_poll_get_char(struct tty_driver
*driver
, int line
)
2234 struct uart_driver
*drv
= driver
->driver_state
;
2235 struct uart_state
*state
= drv
->state
+ line
;
2236 struct uart_port
*port
;
2238 if (!state
|| !state
->uart_port
)
2241 port
= state
->uart_port
;
2242 return port
->ops
->poll_get_char(port
);
2245 static void uart_poll_put_char(struct tty_driver
*driver
, int line
, char ch
)
2247 struct uart_driver
*drv
= driver
->driver_state
;
2248 struct uart_state
*state
= drv
->state
+ line
;
2249 struct uart_port
*port
;
2251 if (!state
|| !state
->uart_port
)
2254 port
= state
->uart_port
;
2255 port
->ops
->poll_put_char(port
, ch
);
2259 static const struct tty_operations uart_ops
= {
2261 .close
= uart_close
,
2262 .write
= uart_write
,
2263 .put_char
= uart_put_char
,
2264 .flush_chars
= uart_flush_chars
,
2265 .write_room
= uart_write_room
,
2266 .chars_in_buffer
= uart_chars_in_buffer
,
2267 .flush_buffer
= uart_flush_buffer
,
2268 .ioctl
= uart_ioctl
,
2269 .throttle
= uart_throttle
,
2270 .unthrottle
= uart_unthrottle
,
2271 .send_xchar
= uart_send_xchar
,
2272 .set_termios
= uart_set_termios
,
2273 .set_ldisc
= uart_set_ldisc
,
2275 .start
= uart_start
,
2276 .hangup
= uart_hangup
,
2277 .break_ctl
= uart_break_ctl
,
2278 .wait_until_sent
= uart_wait_until_sent
,
2279 #ifdef CONFIG_PROC_FS
2280 .proc_fops
= &uart_proc_fops
,
2282 .tiocmget
= uart_tiocmget
,
2283 .tiocmset
= uart_tiocmset
,
2284 .get_icount
= uart_get_icount
,
2285 #ifdef CONFIG_CONSOLE_POLL
2286 .poll_init
= uart_poll_init
,
2287 .poll_get_char
= uart_poll_get_char
,
2288 .poll_put_char
= uart_poll_put_char
,
2292 static const struct tty_port_operations uart_port_ops
= {
2293 .carrier_raised
= uart_carrier_raised
,
2294 .dtr_rts
= uart_dtr_rts
,
2298 * uart_register_driver - register a driver with the uart core layer
2299 * @drv: low level driver structure
2301 * Register a uart driver with the core driver. We in turn register
2302 * with the tty layer, and initialise the core driver per-port state.
2304 * We have a proc file in /proc/tty/driver which is named after the
2307 * drv->port should be NULL, and the per-port structures should be
2308 * registered using uart_add_one_port after this call has succeeded.
2310 int uart_register_driver(struct uart_driver
*drv
)
2312 struct tty_driver
*normal
;
2318 * Maybe we should be using a slab cache for this, especially if
2319 * we have a large number of ports to handle.
2321 drv
->state
= kzalloc(sizeof(struct uart_state
) * drv
->nr
, GFP_KERNEL
);
2325 normal
= alloc_tty_driver(drv
->nr
);
2329 drv
->tty_driver
= normal
;
2331 normal
->owner
= drv
->owner
;
2332 normal
->driver_name
= drv
->driver_name
;
2333 normal
->name
= drv
->dev_name
;
2334 normal
->major
= drv
->major
;
2335 normal
->minor_start
= drv
->minor
;
2336 normal
->type
= TTY_DRIVER_TYPE_SERIAL
;
2337 normal
->subtype
= SERIAL_TYPE_NORMAL
;
2338 normal
->init_termios
= tty_std_termios
;
2339 normal
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2340 normal
->init_termios
.c_ispeed
= normal
->init_termios
.c_ospeed
= 9600;
2341 normal
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
2342 normal
->driver_state
= drv
;
2343 tty_set_operations(normal
, &uart_ops
);
2346 * Initialise the UART state(s).
2348 for (i
= 0; i
< drv
->nr
; i
++) {
2349 struct uart_state
*state
= drv
->state
+ i
;
2350 struct tty_port
*port
= &state
->port
;
2352 tty_port_init(port
);
2353 port
->ops
= &uart_port_ops
;
2354 port
->close_delay
= 500; /* .5 seconds */
2355 port
->closing_wait
= 30000; /* 30 seconds */
2356 tasklet_init(&state
->tlet
, uart_tasklet_action
,
2357 (unsigned long)state
);
2360 retval
= tty_register_driver(normal
);
2364 put_tty_driver(normal
);
2372 * uart_unregister_driver - remove a driver from the uart core layer
2373 * @drv: low level driver structure
2375 * Remove all references to a driver from the core driver. The low
2376 * level driver must have removed all its ports via the
2377 * uart_remove_one_port() if it registered them with uart_add_one_port().
2378 * (ie, drv->port == NULL)
2380 void uart_unregister_driver(struct uart_driver
*drv
)
2382 struct tty_driver
*p
= drv
->tty_driver
;
2383 tty_unregister_driver(p
);
2386 drv
->tty_driver
= NULL
;
2389 struct tty_driver
*uart_console_device(struct console
*co
, int *index
)
2391 struct uart_driver
*p
= co
->data
;
2393 return p
->tty_driver
;
2397 * uart_add_one_port - attach a driver-defined port structure
2398 * @drv: pointer to the uart low level driver structure for this port
2399 * @uport: uart port structure to use for this port.
2401 * This allows the driver to register its own uart_port structure
2402 * with the core driver. The main purpose is to allow the low
2403 * level uart drivers to expand uart_port, rather than having yet
2404 * more levels of structures.
2406 int uart_add_one_port(struct uart_driver
*drv
, struct uart_port
*uport
)
2408 struct uart_state
*state
;
2409 struct tty_port
*port
;
2411 struct device
*tty_dev
;
2413 BUG_ON(in_interrupt());
2415 if (uport
->line
>= drv
->nr
)
2418 state
= drv
->state
+ uport
->line
;
2419 port
= &state
->port
;
2421 mutex_lock(&port_mutex
);
2422 mutex_lock(&port
->mutex
);
2423 if (state
->uart_port
) {
2428 state
->uart_port
= uport
;
2429 state
->pm_state
= -1;
2431 uport
->cons
= drv
->cons
;
2432 uport
->state
= state
;
2435 * If this port is a console, then the spinlock is already
2438 if (!(uart_console(uport
) && (uport
->cons
->flags
& CON_ENABLED
))) {
2439 spin_lock_init(&uport
->lock
);
2440 lockdep_set_class(&uport
->lock
, &port_lock_key
);
2443 uart_configure_port(drv
, state
, uport
);
2446 * Register the port whether it's detected or not. This allows
2447 * setserial to be used to alter this ports parameters.
2449 tty_dev
= tty_register_device(drv
->tty_driver
, uport
->line
, uport
->dev
);
2450 if (likely(!IS_ERR(tty_dev
))) {
2451 device_init_wakeup(tty_dev
, 1);
2452 device_set_wakeup_enable(tty_dev
, 0);
2454 printk(KERN_ERR
"Cannot register tty device on line %d\n",
2458 * Ensure UPF_DEAD is not set.
2460 uport
->flags
&= ~UPF_DEAD
;
2463 mutex_unlock(&port
->mutex
);
2464 mutex_unlock(&port_mutex
);
2470 * uart_remove_one_port - detach a driver defined port structure
2471 * @drv: pointer to the uart low level driver structure for this port
2472 * @uport: uart port structure for this port
2474 * This unhooks (and hangs up) the specified port structure from the
2475 * core driver. No further calls will be made to the low-level code
2478 int uart_remove_one_port(struct uart_driver
*drv
, struct uart_port
*uport
)
2480 struct uart_state
*state
= drv
->state
+ uport
->line
;
2481 struct tty_port
*port
= &state
->port
;
2483 BUG_ON(in_interrupt());
2485 if (state
->uart_port
!= uport
)
2486 printk(KERN_ALERT
"Removing wrong port: %p != %p\n",
2487 state
->uart_port
, uport
);
2489 mutex_lock(&port_mutex
);
2492 * Mark the port "dead" - this prevents any opens from
2493 * succeeding while we shut down the port.
2495 mutex_lock(&port
->mutex
);
2496 uport
->flags
|= UPF_DEAD
;
2497 mutex_unlock(&port
->mutex
);
2500 * Remove the devices from the tty layer
2502 tty_unregister_device(drv
->tty_driver
, uport
->line
);
2505 tty_vhangup(port
->tty
);
2508 * Free the port IO and memory resources, if any.
2510 if (uport
->type
!= PORT_UNKNOWN
)
2511 uport
->ops
->release_port(uport
);
2514 * Indicate that there isn't a port here anymore.
2516 uport
->type
= PORT_UNKNOWN
;
2519 * Kill the tasklet, and free resources.
2521 tasklet_kill(&state
->tlet
);
2523 state
->uart_port
= NULL
;
2524 mutex_unlock(&port_mutex
);
2530 * Are the two ports equivalent?
2532 int uart_match_port(struct uart_port
*port1
, struct uart_port
*port2
)
2534 if (port1
->iotype
!= port2
->iotype
)
2537 switch (port1
->iotype
) {
2539 return (port1
->iobase
== port2
->iobase
);
2541 return (port1
->iobase
== port2
->iobase
) &&
2542 (port1
->hub6
== port2
->hub6
);
2549 return (port1
->mapbase
== port2
->mapbase
);
2553 EXPORT_SYMBOL(uart_match_port
);
2555 EXPORT_SYMBOL(uart_write_wakeup
);
2556 EXPORT_SYMBOL(uart_register_driver
);
2557 EXPORT_SYMBOL(uart_unregister_driver
);
2558 EXPORT_SYMBOL(uart_suspend_port
);
2559 EXPORT_SYMBOL(uart_resume_port
);
2560 EXPORT_SYMBOL(uart_add_one_port
);
2561 EXPORT_SYMBOL(uart_remove_one_port
);
2563 MODULE_DESCRIPTION("Serial driver core");
2564 MODULE_LICENSE("GPL");