Lines Matching +full:up +full:- +full:to

1 /* SPDX-License-Identifier: GPL-2.0-or-later */
25 ((port)->cons && (port)->cons->index == (port)->line)
37 * struct uart_ops -- interface between serial_core and the driver
55 * This function sets the modem control lines for @port to the state
58 * - %TIOCM_RTS RTS signal.
59 * - %TIOCM_DTR DTR signal.
60 * - %TIOCM_OUT1 OUT1 signal.
61 * - %TIOCM_OUT2 OUT2 signal.
62 * - %TIOCM_LOOP Set the port into loopback mode.
68 * Locking: @port->lock taken.
78 * - %TIOCM_CAR state of DCD signal
79 * - %TIOCM_CTS state of CTS signal
80 * - %TIOCM_DSR state of DSR signal
81 * - %TIOCM_RI state of RI signal
88 * Locking: @port->lock taken.
94 * Stop transmitting characters. This might be due to the CTS line
95 * becoming inactive or the tty layer indicating we want to stop
96 * transmission due to an %XOFF character.
100 * Locking: @port->lock taken.
108 * Locking: @port->lock taken.
115 * close to full, and it should somehow signal that no more characters
116 * should be sent to the serial port.
124 * Notify the serial driver that characters can now be sent to the serial
136 * is used to implement XON/XOFF flow control and tcflow(). If the serial
138 * character to the circular buffer and then call start_tx() / stop_tx()
139 * to flush the data out.
150 * Locking: @port->lock taken.
158 * Locking: @port->lock taken.
169 * Locking: @port->lock taken.
179 * Locking: caller holds tty_port->mutex
185 * this will be done via a separate call to @set_mctrl().
196 * this will have already been done via a separate call to @set_mctrl().
198 * Drivers must not access @port->state once this call has completed.
211 * This will be called whenever the @port->state->xmit circular buffer is
214 * Locking: @port->lock taken.
222 * Update @port->read_status_mask and @port->ignore_status_mask to
226 * - %CSIZE - word size
227 * - %CSTOPB - 2 stop bits
228 * - %PARENB - parity enable
229 * - %PARODD - odd parity (when %PARENB is in force)
230 * - %ADDRB - address bit (changed through uart_port::rs485_config()).
231 * - %CREAD - enable reception of characters (if not set, still receive
233 * - %CRTSCTS - if set, enable CTS status change reporting.
234 * - %CLOCAL - if not set, enable modem status change reporting.
238 * - %INPCK - enable frame and parity error events to be passed to the TTY
240 * - %BRKINT / %PARMRK - both of these enable break events to be passed to
242 * - %IGNPAR - ignore parity and framing errors.
243 * - %IGNBRK - ignore break errors. If %IGNPAR is also set, ignore overrun
261 * Locking: caller holds tty_port->mutex
268 * Documentation/driver-api/tty/tty_ldisc.rst.
270 * Locking: caller holds tty_port->mutex
279 * This function should not be used to grab any resources.
290 * Return a pointer to a string constant describing the specified @port,
308 * it should return -%EBUSY on failure.
318 * @port->type should be set to the type found, or %PORT_UNKNOWN if no
349 * Called by kgdb to perform the minimal hardware initialization needed to
353 * Locking: %tty_mutex and tty_port->mutex taken.
358 * Called by kgdb to write a single character @ch directly to the serial
367 * Called by kgdb to read a single character directly from the serial
477 #define UPIO_MEM (SERIAL_IO_MEM) /* driver-specific */
491 struct uart_state *state; /* pointer to parent state */
499 * These flags must be equivalent to the flags defined in
505 * The remaining bits are serial-core specific and not modifiable by
528 /* Port has hardware-assisted h/w flow control */
532 /* Port has hardware-assisted s/w flow control */
551 #error Change mask not equivalent to userspace-visible bit defines
555 * Must hold termios_rwsem, port mutex and port lock to change;
556 * can hold any one lock to read.
567 bool hw_stopped; /* sw-assisted CTS flow state */
600 * Only for console->device_lock()/_unlock() callbacks and internal
603 static inline void __uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags) in __uart_port_lock_irqsave() argument
605 spin_lock_irqsave(&up->lock, *flags); in __uart_port_lock_irqsave()
609 * Only for console->device_lock()/_unlock() callbacks and internal
612 static inline void __uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags) in __uart_port_unlock_irqrestore() argument
614 spin_unlock_irqrestore(&up->lock, flags); in __uart_port_unlock_irqrestore()
618 * uart_port_set_cons - Safely set the @cons field for a uart
619 * @up: The uart port to set
620 * @con: The new console to set to
622 * This function must be used to set @up->cons. It uses the port lock to
623 * synchronize with the port lock wrappers in order to ensure that the console
626 static inline void uart_port_set_cons(struct uart_port *up, struct console *con) in uart_port_set_cons() argument
630 __uart_port_lock_irqsave(up, &flags); in uart_port_set_cons()
631 up->cons = con; in uart_port_set_cons()
632 __uart_port_unlock_irqrestore(up, flags); in uart_port_set_cons()
636 static inline bool __uart_port_using_nbcon(struct uart_port *up) in __uart_port_using_nbcon() argument
638 lockdep_assert_held_once(&up->lock); in __uart_port_using_nbcon()
640 if (likely(!uart_console(up))) in __uart_port_using_nbcon()
644 * @up->cons is only modified under the port lock. Therefore it is in __uart_port_using_nbcon()
647 * @up->cons->node is added/removed from the console list under the in __uart_port_using_nbcon()
649 * cannot change here, thus @up->cons->flags can be read directly. in __uart_port_using_nbcon()
651 if (hlist_unhashed_lockless(&up->cons->node) || in __uart_port_using_nbcon()
652 !(up->cons->flags & CON_NBCON) || in __uart_port_using_nbcon()
653 !up->cons->write_atomic) { in __uart_port_using_nbcon()
661 static inline bool __uart_port_nbcon_try_acquire(struct uart_port *up) in __uart_port_nbcon_try_acquire() argument
663 if (!__uart_port_using_nbcon(up)) in __uart_port_nbcon_try_acquire()
666 return nbcon_device_try_acquire(up->cons); in __uart_port_nbcon_try_acquire()
670 static inline void __uart_port_nbcon_acquire(struct uart_port *up) in __uart_port_nbcon_acquire() argument
672 if (!__uart_port_using_nbcon(up)) in __uart_port_nbcon_acquire()
675 while (!nbcon_device_try_acquire(up->cons)) in __uart_port_nbcon_acquire()
680 static inline void __uart_port_nbcon_release(struct uart_port *up) in __uart_port_nbcon_release() argument
682 if (!__uart_port_using_nbcon(up)) in __uart_port_nbcon_release()
685 nbcon_device_release(up->cons); in __uart_port_nbcon_release()
689 * uart_port_lock - Lock the UART port
690 * @up: Pointer to UART port structure
692 static inline void uart_port_lock(struct uart_port *up) in uart_port_lock() argument
694 spin_lock(&up->lock); in uart_port_lock()
695 __uart_port_nbcon_acquire(up); in uart_port_lock()
699 * uart_port_lock_irq - Lock the UART port and disable interrupts
700 * @up: Pointer to UART port structure
702 static inline void uart_port_lock_irq(struct uart_port *up) in uart_port_lock_irq() argument
704 spin_lock_irq(&up->lock); in uart_port_lock_irq()
705 __uart_port_nbcon_acquire(up); in uart_port_lock_irq()
709 * uart_port_lock_irqsave - Lock the UART port, save and disable interrupts
710 * @up: Pointer to UART port structure
711 * @flags: Pointer to interrupt flags storage
713 static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags) in uart_port_lock_irqsave() argument
715 spin_lock_irqsave(&up->lock, *flags); in uart_port_lock_irqsave()
716 __uart_port_nbcon_acquire(up); in uart_port_lock_irqsave()
720 * uart_port_trylock - Try to lock the UART port
721 * @up: Pointer to UART port structure
725 static inline bool uart_port_trylock(struct uart_port *up) in uart_port_trylock() argument
727 if (!spin_trylock(&up->lock)) in uart_port_trylock()
730 if (!__uart_port_nbcon_try_acquire(up)) { in uart_port_trylock()
731 spin_unlock(&up->lock); in uart_port_trylock()
739 * uart_port_trylock_irqsave - Try to lock the UART port, save and disable interrupts
740 * @up: Pointer to UART port structure
741 * @flags: Pointer to interrupt flags storage
745 static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long *flags) in uart_port_trylock_irqsave() argument
747 if (!spin_trylock_irqsave(&up->lock, *flags)) in uart_port_trylock_irqsave()
750 if (!__uart_port_nbcon_try_acquire(up)) { in uart_port_trylock_irqsave()
751 spin_unlock_irqrestore(&up->lock, *flags); in uart_port_trylock_irqsave()
759 * uart_port_unlock - Unlock the UART port
760 * @up: Pointer to UART port structure
762 static inline void uart_port_unlock(struct uart_port *up) in uart_port_unlock() argument
764 __uart_port_nbcon_release(up); in uart_port_unlock()
765 spin_unlock(&up->lock); in uart_port_unlock()
769 * uart_port_unlock_irq - Unlock the UART port and re-enable interrupts
770 * @up: Pointer to UART port structure
772 static inline void uart_port_unlock_irq(struct uart_port *up) in uart_port_unlock_irq() argument
774 __uart_port_nbcon_release(up); in uart_port_unlock_irq()
775 spin_unlock_irq(&up->lock); in uart_port_unlock_irq()
779 * uart_port_unlock_irqrestore - Unlock the UART port, restore interrupts
780 * @up: Pointer to UART port structure
783 static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags) in uart_port_unlock_irqrestore() argument
785 __uart_port_nbcon_release(up); in uart_port_unlock_irqrestore()
786 spin_unlock_irqrestore(&up->lock, flags); in uart_port_unlock_irqrestore()
789 static inline int serial_port_in(struct uart_port *up, int offset) in serial_port_in() argument
791 return up->serial_in(up, offset); in serial_port_in()
794 static inline void serial_port_out(struct uart_port *up, int offset, int value) in serial_port_out() argument
796 up->serial_out(up, offset, value); in serial_port_out()
800 * enum uart_pm_state - power states for UARTs
801 * @UART_PM_STATE_ON: UART is powered, up and operational
831 * uart_xmit_advance - Advance xmit buffer and account Tx'ed chars
832 * @up: uart_port structure describing the port
837 * @up's icount.tx).
839 static inline void uart_xmit_advance(struct uart_port *up, unsigned int chars) in uart_xmit_advance() argument
841 struct tty_port *tport = &up->state->port; in uart_xmit_advance()
843 kfifo_skip_count(&tport->xmit_fifo, chars); in uart_xmit_advance()
844 up->icount.tx += chars; in uart_xmit_advance()
847 static inline unsigned int uart_fifo_out(struct uart_port *up, in uart_fifo_out() argument
850 struct tty_port *tport = &up->state->port; in uart_fifo_out()
852 chars = kfifo_out(&tport->xmit_fifo, buf, chars); in uart_fifo_out()
853 up->icount.tx += chars; in uart_fifo_out()
858 static inline unsigned int uart_fifo_get(struct uart_port *up, in uart_fifo_get() argument
861 struct tty_port *tport = &up->state->port; in uart_fifo_get()
864 chars = kfifo_get(&tport->xmit_fifo, ch); in uart_fifo_get()
865 up->icount.tx += chars; in uart_fifo_get()
884 * touch these; they should be initialised to NULL
893 * enum UART_TX_FLAGS -- flags for uart_port_tx_flags()
895 * @UART_TX_NOSTOP: don't call port->ops->stop_tx() on empty buffer
905 struct tty_port *__tport = &__port->state->port; \
908 for (; (for_test) && (tx_ready); (for_post), __port->icount.tx++) { \
909 if (__port->x_char) { \
910 (ch) = __port->x_char; \
912 __port->x_char = 0; \
919 if (!kfifo_get(&__tport->xmit_fifo, &(ch))) \
927 pending = kfifo_len(&__tport->xmit_fifo); \
932 __port->ops->stop_tx(__port); \
939 * uart_port_tx_limited -- transmit helper for uart_port with count limiting
941 * @ch: variable to store a character to be written to the HW
942 * @count: a limit of characters to send
944 * @put_char: function to write a character
945 * @tx_done: function to call after the loop is done
947 * This helper transmits characters from the xmit buffer to the hardware using
949 * evaluates to true.
954 * * **tx_ready:** should evaluate to true if the HW can accept more data to
956 * * **put_char:** shall write @ch to the device of @port.
958 * action before potential invocation of ops->stop_tx() happens. If the
959 * driver does not need to do anything, use e.g. ({}).
961 * For all of them, @port->lock is held, interrupts are locally disabled and
967 __count--); \
971 * uart_port_tx_limited_flags -- transmit helper for uart_port with count limiting with flags
973 * @ch: variable to store a character to be written to the HW
975 * @count: a limit of characters to send
977 * @put_char: function to write a character
978 * @tx_done: function to call after the loop is done
985 __count--); \
989 * uart_port_tx -- transmit helper for uart_port
991 * @ch: variable to store a character to be written to the HW
993 * @put_char: function to write a character
1002 * uart_port_tx_flags -- transmit helper for uart_port with flags
1004 * @ch: variable to store a character to be written to the HW
1007 * @put_char: function to write a character
1028 u64 fifo_timeout = (u64)READ_ONCE(port->frame_time) * port->fifosize; in uart_fifo_timeout()
1041 return timeout > 6 ? (timeout / 2 - 2) : 1; in uart_poll_timeout()
1094 return uart_console(port) && console_is_registered_locked(port->cons); in uart_console_registered_locked()
1099 return uart_console(port) && console_is_registered(port->cons); in uart_console_registered()
1135 struct tty_struct *tty = port->state->port.tty; in uart_tx_stopped()
1136 if ((tty && tty->flow.stopped) || port->hw_stopped) in uart_tx_stopped()
1143 return !!(uport->status & UPSTAT_CTS_ENABLE); in uart_cts_enabled()
1150 return ((uport->status & mask) == UPSTAT_CTS_ENABLE); in uart_softcts_mode()
1172 if (!port->sysrq) in uart_handle_sysrq_char()
1175 if (ch && time_before(jiffies, port->sysrq)) { in uart_handle_sysrq_char()
1178 port->sysrq = 0; in uart_handle_sysrq_char()
1184 port->sysrq = 0; in uart_handle_sysrq_char()
1191 if (!port->sysrq) in uart_prepare_sysrq_char()
1194 if (ch && time_before(jiffies, port->sysrq)) { in uart_prepare_sysrq_char()
1196 port->sysrq_ch = ch; in uart_prepare_sysrq_char()
1197 port->sysrq = 0; in uart_prepare_sysrq_char()
1203 port->sysrq = 0; in uart_prepare_sysrq_char()
1212 if (!port->has_sysrq) { in uart_unlock_and_check_sysrq()
1217 sysrq_ch = port->sysrq_ch; in uart_unlock_and_check_sysrq()
1218 port->sysrq_ch = 0; in uart_unlock_and_check_sysrq()
1231 if (!port->has_sysrq) { in uart_unlock_and_check_sysrq_irqrestore()
1236 sysrq_ch = port->sysrq_ch; in uart_unlock_and_check_sysrq_irqrestore()
1237 port->sysrq_ch = 0; in uart_unlock_and_check_sysrq_irqrestore()
1269 struct uart_state *state = port->state; in uart_handle_break()
1271 if (port->handle_break) in uart_handle_break()
1272 port->handle_break(port); in uart_handle_break()
1275 if (port->has_sysrq && uart_console(port)) { in uart_handle_break()
1276 if (!port->sysrq) { in uart_handle_break()
1277 port->sysrq = jiffies + SYSRQ_TIMEOUT; in uart_handle_break()
1280 port->sysrq = 0; in uart_handle_break()
1283 if (port->flags & UPF_SAK) in uart_handle_break()
1284 do_SAK(state->port.tty); in uart_handle_break()
1289 * UART_ENABLE_MS - determine if port should enable modem status irqs
1291 #define UART_ENABLE_MS(port,cflag) ((port)->flags & UPF_HARDPPS_CD || \