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/smp_lock.h>
33 #include <linux/device.h>
34 #include <linux/serial.h> /* for serial_state and serial_icounter_struct */
35 #include <linux/serial_core.h>
36 #include <linux/delay.h>
37 #include <linux/mutex.h>
40 #include <asm/uaccess.h>
43 * This is used to lock changes in serial line configuration.
45 static DEFINE_MUTEX(port_mutex
);
48 * lockdep: port->lock is initialized in two places, but we
49 * want only one lock-class:
51 static struct lock_class_key port_lock_key
;
53 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
55 #define uart_users(state) ((state)->port.count + (state)->port.blocked_open)
57 #ifdef CONFIG_SERIAL_CORE_CONSOLE
58 #define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line)
60 #define uart_console(port) (0)
63 static void uart_change_speed(struct uart_state
*state
,
64 struct ktermios
*old_termios
);
65 static void uart_wait_until_sent(struct tty_struct
*tty
, int timeout
);
66 static void uart_change_pm(struct uart_state
*state
, int pm_state
);
69 * This routine is used by the interrupt handler to schedule processing in
70 * the software interrupt portion of the driver.
72 void uart_write_wakeup(struct uart_port
*port
)
74 struct uart_state
*state
= port
->state
;
76 * This means you called this function _after_ the port was
77 * closed. No cookie for you.
80 tasklet_schedule(&state
->tlet
);
83 static void uart_stop(struct tty_struct
*tty
)
85 struct uart_state
*state
= tty
->driver_data
;
86 struct uart_port
*port
= state
->uart_port
;
89 spin_lock_irqsave(&port
->lock
, flags
);
90 port
->ops
->stop_tx(port
);
91 spin_unlock_irqrestore(&port
->lock
, flags
);
94 static void __uart_start(struct tty_struct
*tty
)
96 struct uart_state
*state
= tty
->driver_data
;
97 struct uart_port
*port
= state
->uart_port
;
99 if (!uart_circ_empty(&state
->xmit
) && state
->xmit
.buf
&&
100 !tty
->stopped
&& !tty
->hw_stopped
)
101 port
->ops
->start_tx(port
);
104 static void uart_start(struct tty_struct
*tty
)
106 struct uart_state
*state
= tty
->driver_data
;
107 struct uart_port
*port
= state
->uart_port
;
110 spin_lock_irqsave(&port
->lock
, flags
);
112 spin_unlock_irqrestore(&port
->lock
, flags
);
115 static void uart_tasklet_action(unsigned long data
)
117 struct uart_state
*state
= (struct uart_state
*)data
;
118 tty_wakeup(state
->port
.tty
);
122 uart_update_mctrl(struct uart_port
*port
, unsigned int set
, unsigned int clear
)
127 spin_lock_irqsave(&port
->lock
, flags
);
129 port
->mctrl
= (old
& ~clear
) | set
;
130 if (old
!= port
->mctrl
)
131 port
->ops
->set_mctrl(port
, port
->mctrl
);
132 spin_unlock_irqrestore(&port
->lock
, flags
);
135 #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0)
136 #define uart_clear_mctrl(port, clear) uart_update_mctrl(port, 0, clear)
139 * Startup the port. This will be called once per open. All calls
140 * will be serialised by the per-port mutex.
142 static int uart_startup(struct uart_state
*state
, int init_hw
)
144 struct uart_port
*uport
= state
->uart_port
;
145 struct tty_port
*port
= &state
->port
;
149 if (port
->flags
& ASYNC_INITIALIZED
)
153 * Set the TTY IO error marker - we will only clear this
154 * once we have successfully opened the port. Also set
155 * up the tty->alt_speed kludge
157 set_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
159 if (uport
->type
== PORT_UNKNOWN
)
163 * Initialise and allocate the transmit and temporary
166 if (!state
->xmit
.buf
) {
167 /* This is protected by the per port mutex */
168 page
= get_zeroed_page(GFP_KERNEL
);
172 state
->xmit
.buf
= (unsigned char *) page
;
173 uart_circ_clear(&state
->xmit
);
176 retval
= uport
->ops
->startup(uport
);
180 * Initialise the hardware port settings.
182 uart_change_speed(state
, NULL
);
185 * Setup the RTS and DTR signals once the
186 * port is open and ready to respond.
188 if (port
->tty
->termios
->c_cflag
& CBAUD
)
189 uart_set_mctrl(uport
, TIOCM_RTS
| TIOCM_DTR
);
192 if (port
->flags
& ASYNC_CTS_FLOW
) {
193 spin_lock_irq(&uport
->lock
);
194 if (!(uport
->ops
->get_mctrl(uport
) & TIOCM_CTS
))
195 port
->tty
->hw_stopped
= 1;
196 spin_unlock_irq(&uport
->lock
);
199 set_bit(ASYNCB_INITIALIZED
, &port
->flags
);
201 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
204 if (retval
&& capable(CAP_SYS_ADMIN
))
211 * This routine will shutdown a serial port; interrupts are disabled, and
212 * DTR is dropped if the hangup on close termio flag is on. Calls to
213 * uart_shutdown are serialised by the per-port semaphore.
215 static void uart_shutdown(struct uart_state
*state
)
217 struct uart_port
*uport
= state
->uart_port
;
218 struct tty_struct
*tty
= state
->port
.tty
;
221 * Set the TTY IO error marker
224 set_bit(TTY_IO_ERROR
, &tty
->flags
);
226 if (test_and_clear_bit(ASYNCB_INITIALIZED
, &state
->port
.flags
)) {
228 * Turn off DTR and RTS early.
230 if (!tty
|| (tty
->termios
->c_cflag
& HUPCL
))
231 uart_clear_mctrl(uport
, TIOCM_DTR
| TIOCM_RTS
);
234 * clear delta_msr_wait queue to avoid mem leaks: we may free
235 * the irq here so the queue might never be woken up. Note
236 * that we won't end up waiting on delta_msr_wait again since
237 * any outstanding file descriptors should be pointing at
238 * hung_up_tty_fops now.
240 wake_up_interruptible(&state
->delta_msr_wait
);
243 * Free the IRQ and disable the port.
245 uport
->ops
->shutdown(uport
);
248 * Ensure that the IRQ handler isn't running on another CPU.
250 synchronize_irq(uport
->irq
);
254 * kill off our tasklet
256 tasklet_kill(&state
->tlet
);
259 * Free the transmit buffer page.
261 if (state
->xmit
.buf
) {
262 free_page((unsigned long)state
->xmit
.buf
);
263 state
->xmit
.buf
= NULL
;
268 * uart_update_timeout - update per-port FIFO timeout.
269 * @port: uart_port structure describing the port
270 * @cflag: termios cflag value
271 * @baud: speed of the port
273 * Set the port FIFO timeout value. The @cflag value should
274 * reflect the actual hardware settings.
277 uart_update_timeout(struct uart_port
*port
, unsigned int cflag
,
282 /* byte size and parity */
283 switch (cflag
& CSIZE
) {
304 * The total number of bits to be transmitted in the fifo.
306 bits
= bits
* port
->fifosize
;
309 * Figure the timeout to send the above number of bits.
310 * Add .02 seconds of slop
312 port
->timeout
= (HZ
* bits
) / baud
+ HZ
/50;
315 EXPORT_SYMBOL(uart_update_timeout
);
318 * uart_get_baud_rate - return baud rate for a particular port
319 * @port: uart_port structure describing the port in question.
320 * @termios: desired termios settings.
321 * @old: old termios (or NULL)
322 * @min: minimum acceptable baud rate
323 * @max: maximum acceptable baud rate
325 * Decode the termios structure into a numeric baud rate,
326 * taking account of the magic 38400 baud rate (with spd_*
327 * flags), and mapping the %B0 rate to 9600 baud.
329 * If the new baud rate is invalid, try the old termios setting.
330 * If it's still invalid, we try 9600 baud.
332 * Update the @termios structure to reflect the baud rate
333 * we're actually going to be using. Don't do this for the case
334 * where B0 is requested ("hang up").
337 uart_get_baud_rate(struct uart_port
*port
, struct ktermios
*termios
,
338 struct ktermios
*old
, unsigned int min
, unsigned int max
)
340 unsigned int try, baud
, altbaud
= 38400;
342 upf_t flags
= port
->flags
& UPF_SPD_MASK
;
344 if (flags
== UPF_SPD_HI
)
346 if (flags
== UPF_SPD_VHI
)
348 if (flags
== UPF_SPD_SHI
)
350 if (flags
== UPF_SPD_WARP
)
353 for (try = 0; try < 2; try++) {
354 baud
= tty_termios_baud_rate(termios
);
357 * The spd_hi, spd_vhi, spd_shi, spd_warp kludge...
364 * Special case: B0 rate.
371 if (baud
>= min
&& baud
<= max
)
375 * Oops, the quotient was zero. Try again with
376 * the old baud rate if possible.
378 termios
->c_cflag
&= ~CBAUD
;
380 baud
= tty_termios_baud_rate(old
);
382 tty_termios_encode_baud_rate(termios
,
389 * As a last resort, if the quotient is zero,
390 * default to 9600 bps
393 tty_termios_encode_baud_rate(termios
, 9600, 9600);
399 EXPORT_SYMBOL(uart_get_baud_rate
);
402 * uart_get_divisor - return uart clock divisor
403 * @port: uart_port structure describing the port.
404 * @baud: desired baud rate
406 * Calculate the uart clock divisor for the port.
409 uart_get_divisor(struct uart_port
*port
, unsigned int baud
)
414 * Old custom speed handling.
416 if (baud
== 38400 && (port
->flags
& UPF_SPD_MASK
) == UPF_SPD_CUST
)
417 quot
= port
->custom_divisor
;
419 quot
= (port
->uartclk
+ (8 * baud
)) / (16 * baud
);
424 EXPORT_SYMBOL(uart_get_divisor
);
426 /* FIXME: Consistent locking policy */
428 uart_change_speed(struct uart_state
*state
, struct ktermios
*old_termios
)
430 struct tty_port
*port
= &state
->port
;
431 struct tty_struct
*tty
= port
->tty
;
432 struct uart_port
*uport
= state
->uart_port
;
433 struct ktermios
*termios
;
436 * If we have no tty, termios, or the port does not exist,
437 * then we can't set the parameters for this port.
439 if (!tty
|| !tty
->termios
|| uport
->type
== PORT_UNKNOWN
)
442 termios
= tty
->termios
;
445 * Set flags based on termios cflag
447 if (termios
->c_cflag
& CRTSCTS
)
448 set_bit(ASYNCB_CTS_FLOW
, &port
->flags
);
450 clear_bit(ASYNCB_CTS_FLOW
, &port
->flags
);
452 if (termios
->c_cflag
& CLOCAL
)
453 clear_bit(ASYNCB_CHECK_CD
, &port
->flags
);
455 set_bit(ASYNCB_CHECK_CD
, &port
->flags
);
457 uport
->ops
->set_termios(uport
, termios
, old_termios
);
461 __uart_put_char(struct uart_port
*port
, struct circ_buf
*circ
, unsigned char c
)
469 spin_lock_irqsave(&port
->lock
, flags
);
470 if (uart_circ_chars_free(circ
) != 0) {
471 circ
->buf
[circ
->head
] = c
;
472 circ
->head
= (circ
->head
+ 1) & (UART_XMIT_SIZE
- 1);
475 spin_unlock_irqrestore(&port
->lock
, flags
);
479 static int uart_put_char(struct tty_struct
*tty
, unsigned char ch
)
481 struct uart_state
*state
= tty
->driver_data
;
483 return __uart_put_char(state
->uart_port
, &state
->xmit
, ch
);
486 static void uart_flush_chars(struct tty_struct
*tty
)
492 uart_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
494 struct uart_state
*state
= tty
->driver_data
;
495 struct uart_port
*port
;
496 struct circ_buf
*circ
;
501 * This means you called this function _after_ the port was
502 * closed. No cookie for you.
509 port
= state
->uart_port
;
515 spin_lock_irqsave(&port
->lock
, flags
);
517 c
= CIRC_SPACE_TO_END(circ
->head
, circ
->tail
, UART_XMIT_SIZE
);
522 memcpy(circ
->buf
+ circ
->head
, buf
, c
);
523 circ
->head
= (circ
->head
+ c
) & (UART_XMIT_SIZE
- 1);
528 spin_unlock_irqrestore(&port
->lock
, flags
);
534 static int uart_write_room(struct tty_struct
*tty
)
536 struct uart_state
*state
= tty
->driver_data
;
540 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
541 ret
= uart_circ_chars_free(&state
->xmit
);
542 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
546 static int uart_chars_in_buffer(struct tty_struct
*tty
)
548 struct uart_state
*state
= tty
->driver_data
;
552 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
553 ret
= uart_circ_chars_pending(&state
->xmit
);
554 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
558 static void uart_flush_buffer(struct tty_struct
*tty
)
560 struct uart_state
*state
= tty
->driver_data
;
561 struct uart_port
*port
;
565 * This means you called this function _after_ the port was
566 * closed. No cookie for you.
573 port
= state
->uart_port
;
574 pr_debug("uart_flush_buffer(%d) called\n", tty
->index
);
576 spin_lock_irqsave(&port
->lock
, flags
);
577 uart_circ_clear(&state
->xmit
);
578 if (port
->ops
->flush_buffer
)
579 port
->ops
->flush_buffer(port
);
580 spin_unlock_irqrestore(&port
->lock
, flags
);
585 * This function is used to send a high-priority XON/XOFF character to
588 static void uart_send_xchar(struct tty_struct
*tty
, char ch
)
590 struct uart_state
*state
= tty
->driver_data
;
591 struct uart_port
*port
= state
->uart_port
;
594 if (port
->ops
->send_xchar
)
595 port
->ops
->send_xchar(port
, ch
);
599 spin_lock_irqsave(&port
->lock
, flags
);
600 port
->ops
->start_tx(port
);
601 spin_unlock_irqrestore(&port
->lock
, flags
);
606 static void uart_throttle(struct tty_struct
*tty
)
608 struct uart_state
*state
= tty
->driver_data
;
611 uart_send_xchar(tty
, STOP_CHAR(tty
));
613 if (tty
->termios
->c_cflag
& CRTSCTS
)
614 uart_clear_mctrl(state
->uart_port
, TIOCM_RTS
);
617 static void uart_unthrottle(struct tty_struct
*tty
)
619 struct uart_state
*state
= tty
->driver_data
;
620 struct uart_port
*port
= state
->uart_port
;
626 uart_send_xchar(tty
, START_CHAR(tty
));
629 if (tty
->termios
->c_cflag
& CRTSCTS
)
630 uart_set_mctrl(port
, TIOCM_RTS
);
633 static int uart_get_info(struct uart_state
*state
,
634 struct serial_struct __user
*retinfo
)
636 struct uart_port
*uport
= state
->uart_port
;
637 struct tty_port
*port
= &state
->port
;
638 struct serial_struct tmp
;
640 memset(&tmp
, 0, sizeof(tmp
));
642 /* Ensure the state we copy is consistent and no hardware changes
644 mutex_lock(&port
->mutex
);
646 tmp
.type
= uport
->type
;
647 tmp
.line
= uport
->line
;
648 tmp
.port
= uport
->iobase
;
649 if (HIGH_BITS_OFFSET
)
650 tmp
.port_high
= (long) uport
->iobase
>> HIGH_BITS_OFFSET
;
651 tmp
.irq
= uport
->irq
;
652 tmp
.flags
= uport
->flags
;
653 tmp
.xmit_fifo_size
= uport
->fifosize
;
654 tmp
.baud_base
= uport
->uartclk
/ 16;
655 tmp
.close_delay
= port
->close_delay
/ 10;
656 tmp
.closing_wait
= port
->closing_wait
== USF_CLOSING_WAIT_NONE
?
657 ASYNC_CLOSING_WAIT_NONE
:
658 port
->closing_wait
/ 10;
659 tmp
.custom_divisor
= uport
->custom_divisor
;
660 tmp
.hub6
= uport
->hub6
;
661 tmp
.io_type
= uport
->iotype
;
662 tmp
.iomem_reg_shift
= uport
->regshift
;
663 tmp
.iomem_base
= (void *)(unsigned long)uport
->mapbase
;
665 mutex_unlock(&port
->mutex
);
667 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
672 static int uart_set_info(struct uart_state
*state
,
673 struct serial_struct __user
*newinfo
)
675 struct serial_struct new_serial
;
676 struct uart_port
*uport
= state
->uart_port
;
677 struct tty_port
*port
= &state
->port
;
678 unsigned long new_port
;
679 unsigned int change_irq
, change_port
, closing_wait
;
680 unsigned int old_custom_divisor
, close_delay
;
681 upf_t old_flags
, new_flags
;
684 if (copy_from_user(&new_serial
, newinfo
, sizeof(new_serial
)))
687 new_port
= new_serial
.port
;
688 if (HIGH_BITS_OFFSET
)
689 new_port
+= (unsigned long) new_serial
.port_high
<< HIGH_BITS_OFFSET
;
691 new_serial
.irq
= irq_canonicalize(new_serial
.irq
);
692 close_delay
= new_serial
.close_delay
* 10;
693 closing_wait
= new_serial
.closing_wait
== ASYNC_CLOSING_WAIT_NONE
?
694 USF_CLOSING_WAIT_NONE
: new_serial
.closing_wait
* 10;
697 * This semaphore protects port->count. It is also
698 * very useful to prevent opens. Also, take the
699 * port configuration semaphore to make sure that a
700 * module insertion/removal doesn't change anything
703 mutex_lock(&port
->mutex
);
705 change_irq
= !(uport
->flags
& UPF_FIXED_PORT
)
706 && new_serial
.irq
!= uport
->irq
;
709 * Since changing the 'type' of the port changes its resource
710 * allocations, we should treat type changes the same as
713 change_port
= !(uport
->flags
& UPF_FIXED_PORT
)
714 && (new_port
!= uport
->iobase
||
715 (unsigned long)new_serial
.iomem_base
!= uport
->mapbase
||
716 new_serial
.hub6
!= uport
->hub6
||
717 new_serial
.io_type
!= uport
->iotype
||
718 new_serial
.iomem_reg_shift
!= uport
->regshift
||
719 new_serial
.type
!= uport
->type
);
721 old_flags
= uport
->flags
;
722 new_flags
= new_serial
.flags
;
723 old_custom_divisor
= uport
->custom_divisor
;
725 if (!capable(CAP_SYS_ADMIN
)) {
727 if (change_irq
|| change_port
||
728 (new_serial
.baud_base
!= uport
->uartclk
/ 16) ||
729 (close_delay
!= port
->close_delay
) ||
730 (closing_wait
!= port
->closing_wait
) ||
731 (new_serial
.xmit_fifo_size
&&
732 new_serial
.xmit_fifo_size
!= uport
->fifosize
) ||
733 (((new_flags
^ old_flags
) & ~UPF_USR_MASK
) != 0))
735 uport
->flags
= ((uport
->flags
& ~UPF_USR_MASK
) |
736 (new_flags
& UPF_USR_MASK
));
737 uport
->custom_divisor
= new_serial
.custom_divisor
;
742 * Ask the low level driver to verify the settings.
744 if (uport
->ops
->verify_port
)
745 retval
= uport
->ops
->verify_port(uport
, &new_serial
);
747 if ((new_serial
.irq
>= nr_irqs
) || (new_serial
.irq
< 0) ||
748 (new_serial
.baud_base
< 9600))
754 if (change_port
|| change_irq
) {
758 * Make sure that we are the sole user of this port.
760 if (uart_users(state
) > 1)
764 * We need to shutdown the serial port at the old
765 * port/type/irq combination.
767 uart_shutdown(state
);
771 unsigned long old_iobase
, old_mapbase
;
772 unsigned int old_type
, old_iotype
, old_hub6
, old_shift
;
774 old_iobase
= uport
->iobase
;
775 old_mapbase
= uport
->mapbase
;
776 old_type
= uport
->type
;
777 old_hub6
= uport
->hub6
;
778 old_iotype
= uport
->iotype
;
779 old_shift
= uport
->regshift
;
782 * Free and release old regions
784 if (old_type
!= PORT_UNKNOWN
)
785 uport
->ops
->release_port(uport
);
787 uport
->iobase
= new_port
;
788 uport
->type
= new_serial
.type
;
789 uport
->hub6
= new_serial
.hub6
;
790 uport
->iotype
= new_serial
.io_type
;
791 uport
->regshift
= new_serial
.iomem_reg_shift
;
792 uport
->mapbase
= (unsigned long)new_serial
.iomem_base
;
795 * Claim and map the new regions
797 if (uport
->type
!= PORT_UNKNOWN
) {
798 retval
= uport
->ops
->request_port(uport
);
800 /* Always success - Jean II */
805 * If we fail to request resources for the
806 * new port, try to restore the old settings.
808 if (retval
&& old_type
!= PORT_UNKNOWN
) {
809 uport
->iobase
= old_iobase
;
810 uport
->type
= old_type
;
811 uport
->hub6
= old_hub6
;
812 uport
->iotype
= old_iotype
;
813 uport
->regshift
= old_shift
;
814 uport
->mapbase
= old_mapbase
;
815 retval
= uport
->ops
->request_port(uport
);
817 * If we failed to restore the old settings,
821 uport
->type
= PORT_UNKNOWN
;
827 /* Added to return the correct error -Ram Gupta */
833 uport
->irq
= new_serial
.irq
;
834 if (!(uport
->flags
& UPF_FIXED_PORT
))
835 uport
->uartclk
= new_serial
.baud_base
* 16;
836 uport
->flags
= (uport
->flags
& ~UPF_CHANGE_MASK
) |
837 (new_flags
& UPF_CHANGE_MASK
);
838 uport
->custom_divisor
= new_serial
.custom_divisor
;
839 port
->close_delay
= close_delay
;
840 port
->closing_wait
= closing_wait
;
841 if (new_serial
.xmit_fifo_size
)
842 uport
->fifosize
= new_serial
.xmit_fifo_size
;
844 port
->tty
->low_latency
=
845 (uport
->flags
& UPF_LOW_LATENCY
) ? 1 : 0;
849 if (uport
->type
== PORT_UNKNOWN
)
851 if (port
->flags
& ASYNC_INITIALIZED
) {
852 if (((old_flags
^ uport
->flags
) & UPF_SPD_MASK
) ||
853 old_custom_divisor
!= uport
->custom_divisor
) {
855 * If they're setting up a custom divisor or speed,
856 * instead of clearing it, then bitch about it. No
857 * need to rate-limit; it's CAP_SYS_ADMIN only.
859 if (uport
->flags
& UPF_SPD_MASK
) {
862 "%s sets custom speed on %s. This "
863 "is deprecated.\n", current
->comm
,
864 tty_name(port
->tty
, buf
));
866 uart_change_speed(state
, NULL
);
869 retval
= uart_startup(state
, 1);
871 mutex_unlock(&port
->mutex
);
877 * uart_get_lsr_info - get line status register info.
878 * Note: uart_ioctl protects us against hangups.
880 static int uart_get_lsr_info(struct uart_state
*state
,
881 unsigned int __user
*value
)
883 struct uart_port
*uport
= state
->uart_port
;
884 struct tty_port
*port
= &state
->port
;
887 result
= uport
->ops
->tx_empty(uport
);
890 * If we're about to load something into the transmit
891 * register, we'll pretend the transmitter isn't empty to
892 * avoid a race condition (depending on when the transmit
893 * interrupt happens).
896 ((uart_circ_chars_pending(&state
->xmit
) > 0) &&
897 !port
->tty
->stopped
&& !port
->tty
->hw_stopped
))
898 result
&= ~TIOCSER_TEMT
;
900 return put_user(result
, value
);
903 static int uart_tiocmget(struct tty_struct
*tty
, struct file
*file
)
905 struct uart_state
*state
= tty
->driver_data
;
906 struct tty_port
*port
= &state
->port
;
907 struct uart_port
*uport
= state
->uart_port
;
910 mutex_lock(&port
->mutex
);
911 if ((!file
|| !tty_hung_up_p(file
)) &&
912 !(tty
->flags
& (1 << TTY_IO_ERROR
))) {
913 result
= uport
->mctrl
;
915 spin_lock_irq(&uport
->lock
);
916 result
|= uport
->ops
->get_mctrl(uport
);
917 spin_unlock_irq(&uport
->lock
);
919 mutex_unlock(&port
->mutex
);
925 uart_tiocmset(struct tty_struct
*tty
, struct file
*file
,
926 unsigned int set
, unsigned int clear
)
928 struct uart_state
*state
= tty
->driver_data
;
929 struct uart_port
*uport
= state
->uart_port
;
930 struct tty_port
*port
= &state
->port
;
933 mutex_lock(&port
->mutex
);
934 if ((!file
|| !tty_hung_up_p(file
)) &&
935 !(tty
->flags
& (1 << TTY_IO_ERROR
))) {
936 uart_update_mctrl(uport
, set
, clear
);
939 mutex_unlock(&port
->mutex
);
943 static int uart_break_ctl(struct tty_struct
*tty
, int break_state
)
945 struct uart_state
*state
= tty
->driver_data
;
946 struct tty_port
*port
= &state
->port
;
947 struct uart_port
*uport
= state
->uart_port
;
949 mutex_lock(&port
->mutex
);
951 if (uport
->type
!= PORT_UNKNOWN
)
952 uport
->ops
->break_ctl(uport
, break_state
);
954 mutex_unlock(&port
->mutex
);
958 static int uart_do_autoconfig(struct uart_state
*state
)
960 struct uart_port
*uport
= state
->uart_port
;
961 struct tty_port
*port
= &state
->port
;
964 if (!capable(CAP_SYS_ADMIN
))
968 * Take the per-port semaphore. This prevents count from
969 * changing, and hence any extra opens of the port while
970 * we're auto-configuring.
972 if (mutex_lock_interruptible(&port
->mutex
))
976 if (uart_users(state
) == 1) {
977 uart_shutdown(state
);
980 * If we already have a port type configured,
981 * we must release its resources.
983 if (uport
->type
!= PORT_UNKNOWN
)
984 uport
->ops
->release_port(uport
);
986 flags
= UART_CONFIG_TYPE
;
987 if (uport
->flags
& UPF_AUTO_IRQ
)
988 flags
|= UART_CONFIG_IRQ
;
991 * This will claim the ports resources if
994 uport
->ops
->config_port(uport
, flags
);
996 ret
= uart_startup(state
, 1);
998 mutex_unlock(&port
->mutex
);
1003 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1004 * - mask passed in arg for lines of interest
1005 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1006 * Caller should use TIOCGICOUNT to see which one it was
1009 uart_wait_modem_status(struct uart_state
*state
, unsigned long arg
)
1011 struct uart_port
*uport
= state
->uart_port
;
1012 DECLARE_WAITQUEUE(wait
, current
);
1013 struct uart_icount cprev
, cnow
;
1017 * note the counters on entry
1019 spin_lock_irq(&uport
->lock
);
1020 memcpy(&cprev
, &uport
->icount
, sizeof(struct uart_icount
));
1023 * Force modem status interrupts on
1025 uport
->ops
->enable_ms(uport
);
1026 spin_unlock_irq(&uport
->lock
);
1028 add_wait_queue(&state
->delta_msr_wait
, &wait
);
1030 spin_lock_irq(&uport
->lock
);
1031 memcpy(&cnow
, &uport
->icount
, sizeof(struct uart_icount
));
1032 spin_unlock_irq(&uport
->lock
);
1034 set_current_state(TASK_INTERRUPTIBLE
);
1036 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1037 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1038 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1039 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
))) {
1046 /* see if a signal did it */
1047 if (signal_pending(current
)) {
1055 current
->state
= TASK_RUNNING
;
1056 remove_wait_queue(&state
->delta_msr_wait
, &wait
);
1062 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1063 * Return: write counters to the user passed counter struct
1064 * NB: both 1->0 and 0->1 transitions are counted except for
1065 * RI where only 0->1 is counted.
1067 static int uart_get_count(struct uart_state
*state
,
1068 struct serial_icounter_struct __user
*icnt
)
1070 struct serial_icounter_struct icount
;
1071 struct uart_icount cnow
;
1072 struct uart_port
*uport
= state
->uart_port
;
1074 spin_lock_irq(&uport
->lock
);
1075 memcpy(&cnow
, &uport
->icount
, sizeof(struct uart_icount
));
1076 spin_unlock_irq(&uport
->lock
);
1078 icount
.cts
= cnow
.cts
;
1079 icount
.dsr
= cnow
.dsr
;
1080 icount
.rng
= cnow
.rng
;
1081 icount
.dcd
= cnow
.dcd
;
1082 icount
.rx
= cnow
.rx
;
1083 icount
.tx
= cnow
.tx
;
1084 icount
.frame
= cnow
.frame
;
1085 icount
.overrun
= cnow
.overrun
;
1086 icount
.parity
= cnow
.parity
;
1087 icount
.brk
= cnow
.brk
;
1088 icount
.buf_overrun
= cnow
.buf_overrun
;
1090 return copy_to_user(icnt
, &icount
, sizeof(icount
)) ? -EFAULT
: 0;
1094 * Called via sys_ioctl. We can use spin_lock_irq() here.
1097 uart_ioctl(struct tty_struct
*tty
, struct file
*filp
, unsigned int cmd
,
1100 struct uart_state
*state
= tty
->driver_data
;
1101 struct tty_port
*port
= &state
->port
;
1102 void __user
*uarg
= (void __user
*)arg
;
1103 int ret
= -ENOIOCTLCMD
;
1107 * These ioctls don't rely on the hardware to be present.
1111 ret
= uart_get_info(state
, uarg
);
1115 ret
= uart_set_info(state
, uarg
);
1119 ret
= uart_do_autoconfig(state
);
1122 case TIOCSERGWILD
: /* obsolete */
1123 case TIOCSERSWILD
: /* obsolete */
1128 if (ret
!= -ENOIOCTLCMD
)
1131 if (tty
->flags
& (1 << TTY_IO_ERROR
)) {
1137 * The following should only be used when hardware is present.
1141 ret
= uart_wait_modem_status(state
, arg
);
1145 ret
= uart_get_count(state
, uarg
);
1149 if (ret
!= -ENOIOCTLCMD
)
1152 mutex_lock(&port
->mutex
);
1154 if (tty_hung_up_p(filp
)) {
1160 * All these rely on hardware being present and need to be
1161 * protected against the tty being hung up.
1164 case TIOCSERGETLSR
: /* Get line status register */
1165 ret
= uart_get_lsr_info(state
, uarg
);
1169 struct uart_port
*uport
= state
->uart_port
;
1170 if (uport
->ops
->ioctl
)
1171 ret
= uport
->ops
->ioctl(uport
, cmd
, arg
);
1176 mutex_unlock(&port
->mutex
);
1181 static void uart_set_ldisc(struct tty_struct
*tty
)
1183 struct uart_state
*state
= tty
->driver_data
;
1184 struct uart_port
*uport
= state
->uart_port
;
1186 if (uport
->ops
->set_ldisc
)
1187 uport
->ops
->set_ldisc(uport
);
1190 static void uart_set_termios(struct tty_struct
*tty
,
1191 struct ktermios
*old_termios
)
1193 struct uart_state
*state
= tty
->driver_data
;
1194 unsigned long flags
;
1195 unsigned int cflag
= tty
->termios
->c_cflag
;
1199 * These are the bits that are used to setup various
1200 * flags in the low level driver. We can ignore the Bfoo
1201 * bits in c_cflag; c_[io]speed will always be set
1202 * appropriately by set_termios() in tty_ioctl.c
1204 #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1205 if ((cflag
^ old_termios
->c_cflag
) == 0 &&
1206 tty
->termios
->c_ospeed
== old_termios
->c_ospeed
&&
1207 tty
->termios
->c_ispeed
== old_termios
->c_ispeed
&&
1208 RELEVANT_IFLAG(tty
->termios
->c_iflag
^ old_termios
->c_iflag
) == 0) {
1212 uart_change_speed(state
, old_termios
);
1214 /* Handle transition to B0 status */
1215 if ((old_termios
->c_cflag
& CBAUD
) && !(cflag
& CBAUD
))
1216 uart_clear_mctrl(state
->uart_port
, TIOCM_RTS
| TIOCM_DTR
);
1218 /* Handle transition away from B0 status */
1219 if (!(old_termios
->c_cflag
& CBAUD
) && (cflag
& CBAUD
)) {
1220 unsigned int mask
= TIOCM_DTR
;
1221 if (!(cflag
& CRTSCTS
) ||
1222 !test_bit(TTY_THROTTLED
, &tty
->flags
))
1224 uart_set_mctrl(state
->uart_port
, mask
);
1227 /* Handle turning off CRTSCTS */
1228 if ((old_termios
->c_cflag
& CRTSCTS
) && !(cflag
& CRTSCTS
)) {
1229 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
1230 tty
->hw_stopped
= 0;
1232 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
1235 /* Handle turning on CRTSCTS */
1236 if (!(old_termios
->c_cflag
& CRTSCTS
) && (cflag
& CRTSCTS
)) {
1237 spin_lock_irqsave(&state
->uart_port
->lock
, flags
);
1238 if (!(state
->uart_port
->ops
->get_mctrl(state
->uart_port
) & TIOCM_CTS
)) {
1239 tty
->hw_stopped
= 1;
1240 state
->uart_port
->ops
->stop_tx(state
->uart_port
);
1242 spin_unlock_irqrestore(&state
->uart_port
->lock
, flags
);
1246 * No need to wake up processes in open wait, since they
1247 * sample the CLOCAL flag once, and don't recheck it.
1248 * XXX It's not clear whether the current behavior is correct
1249 * or not. Hence, this may change.....
1251 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1252 (tty
->termios
->c_cflag
& CLOCAL
))
1253 wake_up_interruptible(&state
->uart_port
.open_wait
);
1258 * In 2.4.5, calls to this will be serialized via the BKL in
1259 * linux/drivers/char/tty_io.c:tty_release()
1260 * linux/drivers/char/tty_io.c:do_tty_handup()
1262 static void uart_close(struct tty_struct
*tty
, struct file
*filp
)
1264 struct uart_state
*state
= tty
->driver_data
;
1265 struct tty_port
*port
;
1266 struct uart_port
*uport
;
1268 BUG_ON(!kernel_locked());
1270 uport
= state
->uart_port
;
1271 port
= &state
->port
;
1273 pr_debug("uart_close(%d) called\n", uport
->line
);
1275 mutex_lock(&port
->mutex
);
1277 if (tty_hung_up_p(filp
))
1280 if ((tty
->count
== 1) && (port
->count
!= 1)) {
1282 * Uh, oh. tty->count is 1, which means that the tty
1283 * structure will be freed. port->count should always
1284 * be one in these conditions. If it's greater than
1285 * one, we've got real problems, since it means the
1286 * serial port won't be shutdown.
1288 printk(KERN_ERR
"uart_close: bad serial port count; tty->count is 1, "
1289 "port->count is %d\n", port
->count
);
1292 if (--port
->count
< 0) {
1293 printk(KERN_ERR
"uart_close: bad serial port count for %s: %d\n",
1294 tty
->name
, port
->count
);
1301 * Now we wait for the transmit buffer to clear; and we notify
1302 * the line discipline to only process XON/XOFF characters by
1303 * setting tty->closing.
1307 if (port
->closing_wait
!= USF_CLOSING_WAIT_NONE
)
1308 tty_wait_until_sent(tty
, msecs_to_jiffies(port
->closing_wait
));
1311 * At this point, we stop accepting input. To do this, we
1312 * disable the receive line status interrupts.
1314 if (port
->flags
& ASYNC_INITIALIZED
) {
1315 unsigned long flags
;
1316 spin_lock_irqsave(&port
->lock
, flags
);
1317 uport
->ops
->stop_rx(uport
);
1318 spin_unlock_irqrestore(&port
->lock
, flags
);
1320 * Before we drop DTR, make sure the UART transmitter
1321 * has completely drained; this is especially
1322 * important if there is a transmit FIFO!
1324 uart_wait_until_sent(tty
, uport
->timeout
);
1327 uart_shutdown(state
);
1328 uart_flush_buffer(tty
);
1330 tty_ldisc_flush(tty
);
1335 if (port
->blocked_open
) {
1336 if (port
->close_delay
)
1337 msleep_interruptible(port
->close_delay
);
1338 } else if (!uart_console(uport
)) {
1339 uart_change_pm(state
, 3);
1343 * Wake up anyone trying to open this port.
1345 clear_bit(ASYNCB_NORMAL_ACTIVE
, &port
->flags
);
1346 wake_up_interruptible(&port
->open_wait
);
1349 mutex_unlock(&port
->mutex
);
1352 static void uart_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1354 struct uart_state
*state
= tty
->driver_data
;
1355 struct uart_port
*port
= state
->uart_port
;
1356 unsigned long char_time
, expire
;
1358 if (port
->type
== PORT_UNKNOWN
|| port
->fifosize
== 0)
1364 * Set the check interval to be 1/5 of the estimated time to
1365 * send a single character, and make it at least 1. The check
1366 * interval should also be less than the timeout.
1368 * Note: we have to use pretty tight timings here to satisfy
1371 char_time
= (port
->timeout
- HZ
/50) / port
->fifosize
;
1372 char_time
= char_time
/ 5;
1375 if (timeout
&& timeout
< char_time
)
1376 char_time
= timeout
;
1379 * If the transmitter hasn't cleared in twice the approximate
1380 * amount of time to send the entire FIFO, it probably won't
1381 * ever clear. This assumes the UART isn't doing flow
1382 * control, which is currently the case. Hence, if it ever
1383 * takes longer than port->timeout, this is probably due to a
1384 * UART bug of some kind. So, we clamp the timeout parameter at
1387 if (timeout
== 0 || timeout
> 2 * port
->timeout
)
1388 timeout
= 2 * port
->timeout
;
1390 expire
= jiffies
+ timeout
;
1392 pr_debug("uart_wait_until_sent(%d), jiffies=%lu, expire=%lu...\n",
1393 port
->line
, jiffies
, expire
);
1396 * Check whether the transmitter is empty every 'char_time'.
1397 * 'timeout' / 'expire' give us the maximum amount of time
1400 while (!port
->ops
->tx_empty(port
)) {
1401 msleep_interruptible(jiffies_to_msecs(char_time
));
1402 if (signal_pending(current
))
1404 if (time_after(jiffies
, expire
))
1407 set_current_state(TASK_RUNNING
); /* might not be needed */
1412 * This is called with the BKL held in
1413 * linux/drivers/char/tty_io.c:do_tty_hangup()
1414 * We're called from the eventd thread, so we can sleep for
1415 * a _short_ time only.
1417 static void uart_hangup(struct tty_struct
*tty
)
1419 struct uart_state
*state
= tty
->driver_data
;
1420 struct tty_port
*port
= &state
->port
;
1422 BUG_ON(!kernel_locked());
1423 pr_debug("uart_hangup(%d)\n", state
->uart_port
->line
);
1425 mutex_lock(&port
->mutex
);
1426 if (port
->flags
& ASYNC_NORMAL_ACTIVE
) {
1427 uart_flush_buffer(tty
);
1428 uart_shutdown(state
);
1430 clear_bit(ASYNCB_NORMAL_ACTIVE
, &port
->flags
);
1432 wake_up_interruptible(&port
->open_wait
);
1433 wake_up_interruptible(&state
->delta_msr_wait
);
1435 mutex_unlock(&port
->mutex
);
1439 * Copy across the serial console cflag setting into the termios settings
1440 * for the initial open of the port. This allows continuity between the
1441 * kernel settings, and the settings init adopts when it opens the port
1442 * for the first time.
1444 static void uart_update_termios(struct uart_state
*state
)
1446 struct tty_struct
*tty
= state
->port
.tty
;
1447 struct uart_port
*port
= state
->uart_port
;
1449 if (uart_console(port
) && port
->cons
->cflag
) {
1450 tty
->termios
->c_cflag
= port
->cons
->cflag
;
1451 port
->cons
->cflag
= 0;
1455 * If the device failed to grab its irq resources,
1456 * or some other error occurred, don't try to talk
1457 * to the port hardware.
1459 if (!(tty
->flags
& (1 << TTY_IO_ERROR
))) {
1461 * Make termios settings take effect.
1463 uart_change_speed(state
, NULL
);
1466 * And finally enable the RTS and DTR signals.
1468 if (tty
->termios
->c_cflag
& CBAUD
)
1469 uart_set_mctrl(port
, TIOCM_DTR
| TIOCM_RTS
);
1474 * Block the open until the port is ready. We must be called with
1475 * the per-port semaphore held.
1478 uart_block_til_ready(struct file
*filp
, struct uart_state
*state
)
1480 DECLARE_WAITQUEUE(wait
, current
);
1481 struct uart_port
*uport
= state
->uart_port
;
1482 struct tty_port
*port
= &state
->port
;
1485 port
->blocked_open
++;
1488 add_wait_queue(&port
->open_wait
, &wait
);
1490 set_current_state(TASK_INTERRUPTIBLE
);
1493 * If we have been hung up, tell userspace/restart open.
1495 if (tty_hung_up_p(filp
) || port
->tty
== NULL
)
1499 * If the port has been closed, tell userspace/restart open.
1501 if (!(port
->flags
& ASYNC_INITIALIZED
))
1505 * If non-blocking mode is set, or CLOCAL mode is set,
1506 * we don't want to wait for the modem status lines to
1507 * indicate that the port is ready.
1509 * Also, if the port is not enabled/configured, we want
1510 * to allow the open to succeed here. Note that we will
1511 * have set TTY_IO_ERROR for a non-existant port.
1513 if ((filp
->f_flags
& O_NONBLOCK
) ||
1514 (port
->tty
->termios
->c_cflag
& CLOCAL
) ||
1515 (port
->tty
->flags
& (1 << TTY_IO_ERROR
)))
1519 * Set DTR to allow modem to know we're waiting. Do
1520 * not set RTS here - we want to make sure we catch
1521 * the data from the modem.
1523 if (port
->tty
->termios
->c_cflag
& CBAUD
)
1524 uart_set_mctrl(uport
, TIOCM_DTR
);
1527 * and wait for the carrier to indicate that the
1528 * modem is ready for us.
1530 spin_lock_irq(&uport
->lock
);
1531 uport
->ops
->enable_ms(uport
);
1532 mctrl
= uport
->ops
->get_mctrl(uport
);
1533 spin_unlock_irq(&uport
->lock
);
1534 if (mctrl
& TIOCM_CAR
)
1537 mutex_unlock(&port
->mutex
);
1539 mutex_lock(&port
->mutex
);
1541 if (signal_pending(current
))
1544 set_current_state(TASK_RUNNING
);
1545 remove_wait_queue(&port
->open_wait
, &wait
);
1548 port
->blocked_open
--;
1550 if (signal_pending(current
))
1551 return -ERESTARTSYS
;
1553 if (!port
->tty
|| tty_hung_up_p(filp
))
1559 static struct uart_state
*uart_get(struct uart_driver
*drv
, int line
)
1561 struct uart_state
*state
;
1562 struct tty_port
*port
;
1565 state
= drv
->state
+ line
;
1566 port
= &state
->port
;
1567 if (mutex_lock_interruptible(&port
->mutex
)) {
1573 if (!state
->uart_port
|| state
->uart_port
->flags
& UPF_DEAD
) {
1581 mutex_unlock(&port
->mutex
);
1583 return ERR_PTR(ret
);
1587 * calls to uart_open are serialised by the BKL in
1588 * fs/char_dev.c:chrdev_open()
1589 * Note that if this fails, then uart_close() _will_ be called.
1591 * In time, we want to scrap the "opening nonpresent ports"
1592 * behaviour and implement an alternative way for setserial
1593 * to set base addresses/ports/types. This will allow us to
1594 * get rid of a certain amount of extra tests.
1596 static int uart_open(struct tty_struct
*tty
, struct file
*filp
)
1598 struct uart_driver
*drv
= (struct uart_driver
*)tty
->driver
->driver_state
;
1599 struct uart_state
*state
;
1600 struct tty_port
*port
;
1601 int retval
, line
= tty
->index
;
1603 BUG_ON(!kernel_locked());
1604 pr_debug("uart_open(%d) called\n", line
);
1607 * tty->driver->num won't change, so we won't fail here with
1608 * tty->driver_data set to something non-NULL (and therefore
1609 * we won't get caught by uart_close()).
1612 if (line
>= tty
->driver
->num
)
1616 * We take the semaphore inside uart_get to guarantee that we won't
1617 * be re-entered while allocating the state structure, or while we
1618 * request any IRQs that the driver may need. This also has the nice
1619 * side-effect that it delays the action of uart_hangup, so we can
1620 * guarantee that state->port.tty will always contain something
1623 state
= uart_get(drv
, line
);
1624 if (IS_ERR(state
)) {
1625 retval
= PTR_ERR(state
);
1628 port
= &state
->port
;
1631 * Once we set tty->driver_data here, we are guaranteed that
1632 * uart_close() will decrement the driver module use count.
1633 * Any failures from here onwards should not touch the count.
1635 tty
->driver_data
= state
;
1636 state
->uart_port
->state
= state
;
1637 tty
->low_latency
= (state
->uart_port
->flags
& UPF_LOW_LATENCY
) ? 1 : 0;
1642 * If the port is in the middle of closing, bail out now.
1644 if (tty_hung_up_p(filp
)) {
1647 mutex_unlock(&port
->mutex
);
1652 * Make sure the device is in D0 state.
1654 if (port
->count
== 1)
1655 uart_change_pm(state
, 0);
1658 * Start up the serial port.
1660 retval
= uart_startup(state
, 0);
1663 * If we succeeded, wait until the port is ready.
1666 retval
= uart_block_til_ready(filp
, state
);
1667 mutex_unlock(&port
->mutex
);
1670 * If this is the first open to succeed, adjust things to suit.
1672 if (retval
== 0 && !(port
->flags
& ASYNC_NORMAL_ACTIVE
)) {
1673 set_bit(ASYNCB_NORMAL_ACTIVE
, &port
->flags
);
1675 uart_update_termios(state
);
1682 static const char *uart_type(struct uart_port
*port
)
1684 const char *str
= NULL
;
1686 if (port
->ops
->type
)
1687 str
= port
->ops
->type(port
);
1695 #ifdef CONFIG_PROC_FS
1697 static void uart_line_info(struct seq_file
*m
, struct uart_driver
*drv
, int i
)
1699 struct uart_state
*state
= drv
->state
+ i
;
1700 struct tty_port
*port
= &state
->port
;
1702 struct uart_port
*uport
= state
->uart_port
;
1704 unsigned int status
;
1710 mmio
= uport
->iotype
>= UPIO_MEM
;
1711 seq_printf(m
, "%d: uart:%s %s%08llX irq:%d",
1712 uport
->line
, uart_type(uport
),
1713 mmio
? "mmio:0x" : "port:",
1714 mmio
? (unsigned long long)uport
->mapbase
1715 : (unsigned long long)uport
->iobase
,
1718 if (uport
->type
== PORT_UNKNOWN
) {
1723 if (capable(CAP_SYS_ADMIN
)) {
1724 mutex_lock(&port
->mutex
);
1725 pm_state
= state
->pm_state
;
1727 uart_change_pm(state
, 0);
1728 spin_lock_irq(&uport
->lock
);
1729 status
= uport
->ops
->get_mctrl(uport
);
1730 spin_unlock_irq(&uport
->lock
);
1732 uart_change_pm(state
, pm_state
);
1733 mutex_unlock(&port
->mutex
);
1735 seq_printf(m
, " tx:%d rx:%d",
1736 uport
->icount
.tx
, uport
->icount
.rx
);
1737 if (uport
->icount
.frame
)
1738 seq_printf(m
, " fe:%d",
1739 uport
->icount
.frame
);
1740 if (uport
->icount
.parity
)
1741 seq_printf(m
, " pe:%d",
1742 uport
->icount
.parity
);
1743 if (uport
->icount
.brk
)
1744 seq_printf(m
, " brk:%d",
1746 if (uport
->icount
.overrun
)
1747 seq_printf(m
, " oe:%d",
1748 uport
->icount
.overrun
);
1750 #define INFOBIT(bit, str) \
1751 if (uport->mctrl & (bit)) \
1752 strncat(stat_buf, (str), sizeof(stat_buf) - \
1753 strlen(stat_buf) - 2)
1754 #define STATBIT(bit, str) \
1755 if (status & (bit)) \
1756 strncat(stat_buf, (str), sizeof(stat_buf) - \
1757 strlen(stat_buf) - 2)
1761 INFOBIT(TIOCM_RTS
, "|RTS");
1762 STATBIT(TIOCM_CTS
, "|CTS");
1763 INFOBIT(TIOCM_DTR
, "|DTR");
1764 STATBIT(TIOCM_DSR
, "|DSR");
1765 STATBIT(TIOCM_CAR
, "|CD");
1766 STATBIT(TIOCM_RNG
, "|RI");
1770 seq_puts(m
, stat_buf
);
1777 static int uart_proc_show(struct seq_file
*m
, void *v
)
1779 struct tty_driver
*ttydrv
= m
->private;
1780 struct uart_driver
*drv
= ttydrv
->driver_state
;
1783 seq_printf(m
, "serinfo:1.0 driver%s%s revision:%s\n",
1785 for (i
= 0; i
< drv
->nr
; i
++)
1786 uart_line_info(m
, drv
, i
);
1790 static int uart_proc_open(struct inode
*inode
, struct file
*file
)
1792 return single_open(file
, uart_proc_show
, PDE(inode
)->data
);
1795 static const struct file_operations uart_proc_fops
= {
1796 .owner
= THIS_MODULE
,
1797 .open
= uart_proc_open
,
1799 .llseek
= seq_lseek
,
1800 .release
= single_release
,
1804 #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
1806 * uart_console_write - write a console message to a serial port
1807 * @port: the port to write the message
1808 * @s: array of characters
1809 * @count: number of characters in string to write
1810 * @write: function to write character to port
1812 void uart_console_write(struct uart_port
*port
, const char *s
,
1814 void (*putchar
)(struct uart_port
*, int))
1818 for (i
= 0; i
< count
; i
++, s
++) {
1820 putchar(port
, '\r');
1824 EXPORT_SYMBOL_GPL(uart_console_write
);
1827 * Check whether an invalid uart number has been specified, and
1828 * if so, search for the first available port that does have
1831 struct uart_port
* __init
1832 uart_get_console(struct uart_port
*ports
, int nr
, struct console
*co
)
1834 int idx
= co
->index
;
1836 if (idx
< 0 || idx
>= nr
|| (ports
[idx
].iobase
== 0 &&
1837 ports
[idx
].membase
== NULL
))
1838 for (idx
= 0; idx
< nr
; idx
++)
1839 if (ports
[idx
].iobase
!= 0 ||
1840 ports
[idx
].membase
!= NULL
)
1849 * uart_parse_options - Parse serial port baud/parity/bits/flow contro.
1850 * @options: pointer to option string
1851 * @baud: pointer to an 'int' variable for the baud rate.
1852 * @parity: pointer to an 'int' variable for the parity.
1853 * @bits: pointer to an 'int' variable for the number of data bits.
1854 * @flow: pointer to an 'int' variable for the flow control character.
1856 * uart_parse_options decodes a string containing the serial console
1857 * options. The format of the string is <baud><parity><bits><flow>,
1861 uart_parse_options(char *options
, int *baud
, int *parity
, int *bits
, int *flow
)
1865 *baud
= simple_strtoul(s
, NULL
, 10);
1866 while (*s
>= '0' && *s
<= '9')
1875 EXPORT_SYMBOL_GPL(uart_parse_options
);
1882 static const struct baud_rates baud_rates
[] = {
1883 { 921600, B921600
},
1884 { 460800, B460800
},
1885 { 230400, B230400
},
1886 { 115200, B115200
},
1898 * uart_set_options - setup the serial console parameters
1899 * @port: pointer to the serial ports uart_port structure
1900 * @co: console pointer
1902 * @parity: parity character - 'n' (none), 'o' (odd), 'e' (even)
1903 * @bits: number of data bits
1904 * @flow: flow control character - 'r' (rts)
1907 uart_set_options(struct uart_port
*port
, struct console
*co
,
1908 int baud
, int parity
, int bits
, int flow
)
1910 struct ktermios termios
;
1911 static struct ktermios dummy
;
1915 * Ensure that the serial console lock is initialised
1918 spin_lock_init(&port
->lock
);
1919 lockdep_set_class(&port
->lock
, &port_lock_key
);
1921 memset(&termios
, 0, sizeof(struct ktermios
));
1923 termios
.c_cflag
= CREAD
| HUPCL
| CLOCAL
;
1926 * Construct a cflag setting.
1928 for (i
= 0; baud_rates
[i
].rate
; i
++)
1929 if (baud_rates
[i
].rate
<= baud
)
1932 termios
.c_cflag
|= baud_rates
[i
].cflag
;
1935 termios
.c_cflag
|= CS7
;
1937 termios
.c_cflag
|= CS8
;
1941 termios
.c_cflag
|= PARODD
;
1944 termios
.c_cflag
|= PARENB
;
1949 termios
.c_cflag
|= CRTSCTS
;
1952 * some uarts on other side don't support no flow control.
1953 * So we set * DTR in host uart to make them happy
1955 port
->mctrl
|= TIOCM_DTR
;
1957 port
->ops
->set_termios(port
, &termios
, &dummy
);
1959 * Allow the setting of the UART parameters with a NULL console
1963 co
->cflag
= termios
.c_cflag
;
1967 EXPORT_SYMBOL_GPL(uart_set_options
);
1968 #endif /* CONFIG_SERIAL_CORE_CONSOLE */
1970 static void uart_change_pm(struct uart_state
*state
, int pm_state
)
1972 struct uart_port
*port
= state
->uart_port
;
1974 if (state
->pm_state
!= pm_state
) {
1976 port
->ops
->pm(port
, pm_state
, state
->pm_state
);
1977 state
->pm_state
= pm_state
;
1982 struct uart_port
*port
;
1983 struct uart_driver
*driver
;
1986 static int serial_match_port(struct device
*dev
, void *data
)
1988 struct uart_match
*match
= data
;
1989 struct tty_driver
*tty_drv
= match
->driver
->tty_driver
;
1990 dev_t devt
= MKDEV(tty_drv
->major
, tty_drv
->minor_start
) +
1993 return dev
->devt
== devt
; /* Actually, only one tty per port */
1996 int uart_suspend_port(struct uart_driver
*drv
, struct uart_port
*uport
)
1998 struct uart_state
*state
= drv
->state
+ uport
->line
;
1999 struct tty_port
*port
= &state
->port
;
2000 struct device
*tty_dev
;
2001 struct uart_match match
= {uport
, drv
};
2003 mutex_lock(&port
->mutex
);
2005 if (!console_suspend_enabled
&& uart_console(uport
)) {
2006 /* we're going to avoid suspending serial console */
2007 mutex_unlock(&port
->mutex
);
2011 tty_dev
= device_find_child(uport
->dev
, &match
, serial_match_port
);
2012 if (device_may_wakeup(tty_dev
)) {
2013 enable_irq_wake(uport
->irq
);
2014 put_device(tty_dev
);
2015 mutex_unlock(&port
->mutex
);
2018 uport
->suspended
= 1;
2020 if (port
->flags
& ASYNC_INITIALIZED
) {
2021 const struct uart_ops
*ops
= uport
->ops
;
2024 set_bit(ASYNCB_SUSPENDED
, &port
->flags
);
2025 clear_bit(ASYNCB_INITIALIZED
, &port
->flags
);
2027 spin_lock_irq(&uport
->lock
);
2028 ops
->stop_tx(uport
);
2029 ops
->set_mctrl(uport
, 0);
2030 ops
->stop_rx(uport
);
2031 spin_unlock_irq(&uport
->lock
);
2034 * Wait for the transmitter to empty.
2036 for (tries
= 3; !ops
->tx_empty(uport
) && tries
; tries
--)
2039 printk(KERN_ERR
"%s%s%s%d: Unable to drain "
2041 uport
->dev
? dev_name(uport
->dev
) : "",
2042 uport
->dev
? ": " : "",
2044 drv
->tty_driver
->name_base
+ uport
->line
);
2046 ops
->shutdown(uport
);
2050 * Disable the console device before suspending.
2052 if (uart_console(uport
))
2053 console_stop(uport
->cons
);
2055 uart_change_pm(state
, 3);
2057 mutex_unlock(&port
->mutex
);
2062 int uart_resume_port(struct uart_driver
*drv
, struct uart_port
*uport
)
2064 struct uart_state
*state
= drv
->state
+ uport
->line
;
2065 struct tty_port
*port
= &state
->port
;
2066 struct device
*tty_dev
;
2067 struct uart_match match
= {uport
, drv
};
2069 mutex_lock(&port
->mutex
);
2071 if (!console_suspend_enabled
&& uart_console(uport
)) {
2072 /* no need to resume serial console, it wasn't suspended */
2073 mutex_unlock(&port
->mutex
);
2077 tty_dev
= device_find_child(uport
->dev
, &match
, serial_match_port
);
2078 if (!uport
->suspended
&& device_may_wakeup(tty_dev
)) {
2079 disable_irq_wake(uport
->irq
);
2080 mutex_unlock(&port
->mutex
);
2083 uport
->suspended
= 0;
2086 * Re-enable the console device after suspending.
2088 if (uart_console(uport
)) {
2089 struct ktermios termios
;
2092 * First try to use the console cflag setting.
2094 memset(&termios
, 0, sizeof(struct ktermios
));
2095 termios
.c_cflag
= uport
->cons
->cflag
;
2098 * If that's unset, use the tty termios setting.
2100 if (port
->tty
&& termios
.c_cflag
== 0)
2101 termios
= *port
->tty
->termios
;
2103 uart_change_pm(state
, 0);
2104 uport
->ops
->set_termios(uport
, &termios
, NULL
);
2105 console_start(uport
->cons
);
2108 if (port
->flags
& ASYNC_SUSPENDED
) {
2109 const struct uart_ops
*ops
= uport
->ops
;
2112 uart_change_pm(state
, 0);
2113 spin_lock_irq(&uport
->lock
);
2114 ops
->set_mctrl(uport
, 0);
2115 spin_unlock_irq(&uport
->lock
);
2116 ret
= ops
->startup(uport
);
2118 uart_change_speed(state
, NULL
);
2119 spin_lock_irq(&uport
->lock
);
2120 ops
->set_mctrl(uport
, uport
->mctrl
);
2121 ops
->start_tx(uport
);
2122 spin_unlock_irq(&uport
->lock
);
2123 set_bit(ASYNCB_INITIALIZED
, &port
->flags
);
2126 * Failed to resume - maybe hardware went away?
2127 * Clear the "initialized" flag so we won't try
2128 * to call the low level drivers shutdown method.
2130 uart_shutdown(state
);
2133 clear_bit(ASYNCB_SUSPENDED
, &port
->flags
);
2136 mutex_unlock(&port
->mutex
);
2142 uart_report_port(struct uart_driver
*drv
, struct uart_port
*port
)
2146 switch (port
->iotype
) {
2148 snprintf(address
, sizeof(address
), "I/O 0x%lx", port
->iobase
);
2151 snprintf(address
, sizeof(address
),
2152 "I/O 0x%lx offset 0x%x", port
->iobase
, port
->hub6
);
2159 snprintf(address
, sizeof(address
),
2160 "MMIO 0x%llx", (unsigned long long)port
->mapbase
);
2163 strlcpy(address
, "*unknown*", sizeof(address
));
2167 printk(KERN_INFO
"%s%s%s%d at %s (irq = %d) is a %s\n",
2168 port
->dev
? dev_name(port
->dev
) : "",
2169 port
->dev
? ": " : "",
2171 drv
->tty_driver
->name_base
+ port
->line
,
2172 address
, port
->irq
, uart_type(port
));
2176 uart_configure_port(struct uart_driver
*drv
, struct uart_state
*state
,
2177 struct uart_port
*port
)
2182 * If there isn't a port here, don't do anything further.
2184 if (!port
->iobase
&& !port
->mapbase
&& !port
->membase
)
2188 * Now do the auto configuration stuff. Note that config_port
2189 * is expected to claim the resources and map the port for us.
2192 if (port
->flags
& UPF_AUTO_IRQ
)
2193 flags
|= UART_CONFIG_IRQ
;
2194 if (port
->flags
& UPF_BOOT_AUTOCONF
) {
2195 if (!(port
->flags
& UPF_FIXED_TYPE
)) {
2196 port
->type
= PORT_UNKNOWN
;
2197 flags
|= UART_CONFIG_TYPE
;
2199 port
->ops
->config_port(port
, flags
);
2202 if (port
->type
!= PORT_UNKNOWN
) {
2203 unsigned long flags
;
2205 uart_report_port(drv
, port
);
2207 /* Power up port for set_mctrl() */
2208 uart_change_pm(state
, 0);
2211 * Ensure that the modem control lines are de-activated.
2212 * keep the DTR setting that is set in uart_set_options()
2213 * We probably don't need a spinlock around this, but
2215 spin_lock_irqsave(&port
->lock
, flags
);
2216 port
->ops
->set_mctrl(port
, port
->mctrl
& TIOCM_DTR
);
2217 spin_unlock_irqrestore(&port
->lock
, flags
);
2220 * If this driver supports console, and it hasn't been
2221 * successfully registered yet, try to re-register it.
2222 * It may be that the port was not available.
2224 if (port
->cons
&& !(port
->cons
->flags
& CON_ENABLED
))
2225 register_console(port
->cons
);
2228 * Power down all ports by default, except the
2229 * console if we have one.
2231 if (!uart_console(port
))
2232 uart_change_pm(state
, 3);
2236 #ifdef CONFIG_CONSOLE_POLL
2238 static int uart_poll_init(struct tty_driver
*driver
, int line
, char *options
)
2240 struct uart_driver
*drv
= driver
->driver_state
;
2241 struct uart_state
*state
= drv
->state
+ line
;
2242 struct uart_port
*port
;
2248 if (!state
|| !state
->uart_port
)
2251 port
= state
->uart_port
;
2252 if (!(port
->ops
->poll_get_char
&& port
->ops
->poll_put_char
))
2256 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
2257 return uart_set_options(port
, NULL
, baud
, parity
, bits
, flow
);
2263 static int uart_poll_get_char(struct tty_driver
*driver
, int line
)
2265 struct uart_driver
*drv
= driver
->driver_state
;
2266 struct uart_state
*state
= drv
->state
+ line
;
2267 struct uart_port
*port
;
2269 if (!state
|| !state
->uart_port
)
2272 port
= state
->uart_port
;
2273 return port
->ops
->poll_get_char(port
);
2276 static void uart_poll_put_char(struct tty_driver
*driver
, int line
, char ch
)
2278 struct uart_driver
*drv
= driver
->driver_state
;
2279 struct uart_state
*state
= drv
->state
+ line
;
2280 struct uart_port
*port
;
2282 if (!state
|| !state
->uart_port
)
2285 port
= state
->uart_port
;
2286 port
->ops
->poll_put_char(port
, ch
);
2290 static const struct tty_operations uart_ops
= {
2292 .close
= uart_close
,
2293 .write
= uart_write
,
2294 .put_char
= uart_put_char
,
2295 .flush_chars
= uart_flush_chars
,
2296 .write_room
= uart_write_room
,
2297 .chars_in_buffer
= uart_chars_in_buffer
,
2298 .flush_buffer
= uart_flush_buffer
,
2299 .ioctl
= uart_ioctl
,
2300 .throttle
= uart_throttle
,
2301 .unthrottle
= uart_unthrottle
,
2302 .send_xchar
= uart_send_xchar
,
2303 .set_termios
= uart_set_termios
,
2304 .set_ldisc
= uart_set_ldisc
,
2306 .start
= uart_start
,
2307 .hangup
= uart_hangup
,
2308 .break_ctl
= uart_break_ctl
,
2309 .wait_until_sent
= uart_wait_until_sent
,
2310 #ifdef CONFIG_PROC_FS
2311 .proc_fops
= &uart_proc_fops
,
2313 .tiocmget
= uart_tiocmget
,
2314 .tiocmset
= uart_tiocmset
,
2315 #ifdef CONFIG_CONSOLE_POLL
2316 .poll_init
= uart_poll_init
,
2317 .poll_get_char
= uart_poll_get_char
,
2318 .poll_put_char
= uart_poll_put_char
,
2323 * uart_register_driver - register a driver with the uart core layer
2324 * @drv: low level driver structure
2326 * Register a uart driver with the core driver. We in turn register
2327 * with the tty layer, and initialise the core driver per-port state.
2329 * We have a proc file in /proc/tty/driver which is named after the
2332 * drv->port should be NULL, and the per-port structures should be
2333 * registered using uart_add_one_port after this call has succeeded.
2335 int uart_register_driver(struct uart_driver
*drv
)
2337 struct tty_driver
*normal
= NULL
;
2343 * Maybe we should be using a slab cache for this, especially if
2344 * we have a large number of ports to handle.
2346 drv
->state
= kzalloc(sizeof(struct uart_state
) * drv
->nr
, GFP_KERNEL
);
2351 normal
= alloc_tty_driver(drv
->nr
);
2355 drv
->tty_driver
= normal
;
2357 normal
->owner
= drv
->owner
;
2358 normal
->driver_name
= drv
->driver_name
;
2359 normal
->name
= drv
->dev_name
;
2360 normal
->major
= drv
->major
;
2361 normal
->minor_start
= drv
->minor
;
2362 normal
->type
= TTY_DRIVER_TYPE_SERIAL
;
2363 normal
->subtype
= SERIAL_TYPE_NORMAL
;
2364 normal
->init_termios
= tty_std_termios
;
2365 normal
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2366 normal
->init_termios
.c_ispeed
= normal
->init_termios
.c_ospeed
= 9600;
2367 normal
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
2368 normal
->driver_state
= drv
;
2369 tty_set_operations(normal
, &uart_ops
);
2372 * Initialise the UART state(s).
2374 for (i
= 0; i
< drv
->nr
; i
++) {
2375 struct uart_state
*state
= drv
->state
+ i
;
2376 struct tty_port
*port
= &state
->port
;
2378 tty_port_init(port
);
2379 port
->close_delay
= 500; /* .5 seconds */
2380 port
->closing_wait
= 30000; /* 30 seconds */
2381 init_waitqueue_head(&state
->delta_msr_wait
);
2382 tasklet_init(&state
->tlet
, uart_tasklet_action
,
2383 (unsigned long)state
);
2386 retval
= tty_register_driver(normal
);
2389 put_tty_driver(normal
);
2396 * uart_unregister_driver - remove a driver from the uart core layer
2397 * @drv: low level driver structure
2399 * Remove all references to a driver from the core driver. The low
2400 * level driver must have removed all its ports via the
2401 * uart_remove_one_port() if it registered them with uart_add_one_port().
2402 * (ie, drv->port == NULL)
2404 void uart_unregister_driver(struct uart_driver
*drv
)
2406 struct tty_driver
*p
= drv
->tty_driver
;
2407 tty_unregister_driver(p
);
2410 drv
->tty_driver
= NULL
;
2413 struct tty_driver
*uart_console_device(struct console
*co
, int *index
)
2415 struct uart_driver
*p
= co
->data
;
2417 return p
->tty_driver
;
2421 * uart_add_one_port - attach a driver-defined port structure
2422 * @drv: pointer to the uart low level driver structure for this port
2423 * @port: uart port structure to use for this port.
2425 * This allows the driver to register its own uart_port structure
2426 * with the core driver. The main purpose is to allow the low
2427 * level uart drivers to expand uart_port, rather than having yet
2428 * more levels of structures.
2430 int uart_add_one_port(struct uart_driver
*drv
, struct uart_port
*uport
)
2432 struct uart_state
*state
;
2433 struct tty_port
*port
;
2435 struct device
*tty_dev
;
2437 BUG_ON(in_interrupt());
2439 if (uport
->line
>= drv
->nr
)
2442 state
= drv
->state
+ uport
->line
;
2443 port
= &state
->port
;
2445 mutex_lock(&port_mutex
);
2446 mutex_lock(&port
->mutex
);
2447 if (state
->uart_port
) {
2452 state
->uart_port
= uport
;
2453 state
->pm_state
= -1;
2455 uport
->cons
= drv
->cons
;
2456 uport
->state
= state
;
2459 * If this port is a console, then the spinlock is already
2462 if (!(uart_console(uport
) && (uport
->cons
->flags
& CON_ENABLED
))) {
2463 spin_lock_init(&uport
->lock
);
2464 lockdep_set_class(&uport
->lock
, &port_lock_key
);
2467 uart_configure_port(drv
, state
, uport
);
2470 * Register the port whether it's detected or not. This allows
2471 * setserial to be used to alter this ports parameters.
2473 tty_dev
= tty_register_device(drv
->tty_driver
, uport
->line
, uport
->dev
);
2474 if (likely(!IS_ERR(tty_dev
))) {
2475 device_init_wakeup(tty_dev
, 1);
2476 device_set_wakeup_enable(tty_dev
, 0);
2478 printk(KERN_ERR
"Cannot register tty device on line %d\n",
2482 * Ensure UPF_DEAD is not set.
2484 uport
->flags
&= ~UPF_DEAD
;
2487 mutex_unlock(&port
->mutex
);
2488 mutex_unlock(&port_mutex
);
2494 * uart_remove_one_port - detach a driver defined port structure
2495 * @drv: pointer to the uart low level driver structure for this port
2496 * @port: uart port structure for this port
2498 * This unhooks (and hangs up) the specified port structure from the
2499 * core driver. No further calls will be made to the low-level code
2502 int uart_remove_one_port(struct uart_driver
*drv
, struct uart_port
*uport
)
2504 struct uart_state
*state
= drv
->state
+ uport
->line
;
2505 struct tty_port
*port
= &state
->port
;
2507 BUG_ON(in_interrupt());
2509 if (state
->uart_port
!= uport
)
2510 printk(KERN_ALERT
"Removing wrong port: %p != %p\n",
2511 state
->uart_port
, uport
);
2513 mutex_lock(&port_mutex
);
2516 * Mark the port "dead" - this prevents any opens from
2517 * succeeding while we shut down the port.
2519 mutex_lock(&port
->mutex
);
2520 uport
->flags
|= UPF_DEAD
;
2521 mutex_unlock(&port
->mutex
);
2524 * Remove the devices from the tty layer
2526 tty_unregister_device(drv
->tty_driver
, uport
->line
);
2529 tty_vhangup(port
->tty
);
2532 * Free the port IO and memory resources, if any.
2534 if (uport
->type
!= PORT_UNKNOWN
)
2535 uport
->ops
->release_port(uport
);
2538 * Indicate that there isn't a port here anymore.
2540 uport
->type
= PORT_UNKNOWN
;
2543 * Kill the tasklet, and free resources.
2545 tasklet_kill(&state
->tlet
);
2547 state
->uart_port
= NULL
;
2548 mutex_unlock(&port_mutex
);
2554 * Are the two ports equivalent?
2556 int uart_match_port(struct uart_port
*port1
, struct uart_port
*port2
)
2558 if (port1
->iotype
!= port2
->iotype
)
2561 switch (port1
->iotype
) {
2563 return (port1
->iobase
== port2
->iobase
);
2565 return (port1
->iobase
== port2
->iobase
) &&
2566 (port1
->hub6
== port2
->hub6
);
2572 return (port1
->mapbase
== port2
->mapbase
);
2576 EXPORT_SYMBOL(uart_match_port
);
2578 EXPORT_SYMBOL(uart_write_wakeup
);
2579 EXPORT_SYMBOL(uart_register_driver
);
2580 EXPORT_SYMBOL(uart_unregister_driver
);
2581 EXPORT_SYMBOL(uart_suspend_port
);
2582 EXPORT_SYMBOL(uart_resume_port
);
2583 EXPORT_SYMBOL(uart_add_one_port
);
2584 EXPORT_SYMBOL(uart_remove_one_port
);
2586 MODULE_DESCRIPTION("Serial driver core");
2587 MODULE_LICENSE("GPL");