// SPDX-License-Identifier: GPL-2.0-or-later /* * SDIO UART/GPS driver * * Based on drivers/serial/8250.c and drivers/serial/serial_core.c * by Russell King. * * Author: Nicolas Pitre * Created: June 15, 2007 * Copyright: MontaVista Software, Inc.
*/
/* * Note: Although this driver assumes a 16550A-like UART implementation, * it is not possible to leverage the common 8250/16550 driver, nor the * core UART infrastructure, as they assumes direct access to the hardware * registers, often under a spinlock. This is not possible in the SDIO * context as SDIO access functions must be able to sleep. * * Because we need to lock the SDIO host to ensure an exclusive access to * the card, we simply rely on that lock to also prevent and serialize * concurrent access to the same port.
*/
/* * We're killing a port that potentially still is in use by * the tty layer. Be careful to prevent any further access * to the SDIO function and arrange for the tty layer to * give up on that port ASAP. * Beware: the lock ordering is critical.
*/
mutex_lock(&port->port.mutex);
mutex_lock(&port->func_lock);
func = port->func;
sdio_claim_host(func);
port->func = NULL;
mutex_unlock(&port->func_lock); /* tty_hangup is async so is this safe as is ?? */
tty_port_tty_hangup(&port->port, false);
mutex_unlock(&port->port.mutex);
sdio_release_irq(func);
sdio_disable_func(func);
sdio_release_host(func);
/* FIXME: What stops this losing the delta bits and breaking
sdio_uart_check_modem_status ? */
status = sdio_in(port, UART_MSR);
ret = 0; if (status & UART_MSR_DCD)
ret |= TIOCM_CAR; if (status & UART_MSR_RI)
ret |= TIOCM_RNG; if (status & UART_MSR_DSR)
ret |= TIOCM_DSR; if (status & UART_MSR_CTS)
ret |= TIOCM_CTS; return ret;
}
/* * Characters to ignore
*/
port->ignore_status_mask = 0; if (termios->c_iflag & IGNPAR)
port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; if (termios->c_iflag & IGNBRK) {
port->ignore_status_mask |= UART_LSR_BI; /* * If we're ignoring parity and break indicators, * ignore overruns too (for real raw support).
*/ if (termios->c_iflag & IGNPAR)
port->ignore_status_mask |= UART_LSR_OE;
}
/* * ignore all characters if CREAD is not set
*/ if ((termios->c_cflag & CREAD) == 0)
port->ignore_status_mask |= UART_LSR_DR;
/* * CTS flow control flag and modem status interrupts
*/
port->ier &= ~UART_IER_MSI; if ((termios->c_cflag & CRTSCTS) || !(termios->c_cflag & CLOCAL))
port->ier |= UART_IER_MSI;
do {
u8 ch = sdio_in(port, UART_RX);
u8 flag = TTY_NORMAL;
port->icount.rx++;
if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
UART_LSR_FE | UART_LSR_OE))) { /* * For statistics only
*/ if (*status & UART_LSR_BI) {
*status &= ~(UART_LSR_FE | UART_LSR_PE);
port->icount.brk++;
} elseif (*status & UART_LSR_PE)
port->icount.parity++; elseif (*status & UART_LSR_FE)
port->icount.frame++; if (*status & UART_LSR_OE)
port->icount.overrun++;
/* * Mask off conditions which should be ignored.
*/
*status &= port->read_status_mask; if (*status & UART_LSR_BI)
flag = TTY_BREAK; elseif (*status & UART_LSR_PE)
flag = TTY_PARITY; elseif (*status & UART_LSR_FE)
flag = TTY_FRAME;
}
/* * Overrun is special. Since it's reported immediately, * it doesn't affect the current character.
*/ if (*status & ~port->ignore_status_mask & UART_LSR_OE)
tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
if (status & UART_MSR_TERI)
port->icount.rng++; if (status & UART_MSR_DDSR)
port->icount.dsr++; if (status & UART_MSR_DDCD) {
port->icount.dcd++; /* DCD raise - wake for open */ if (status & UART_MSR_DCD)
wake_up_interruptible(&port->port.open_wait); else { /* DCD drop - hang up if tty attached */
tty_port_tty_hangup(&port->port, false);
}
} if (status & UART_MSR_DCTS) {
port->icount.cts++;
tty = tty_port_tty_get(&port->port); if (tty && C_CRTSCTS(tty)) { bool cts = status & UART_MSR_CTS; if (tty->hw_stopped) { if (cts) {
tty->hw_stopped = false;
sdio_uart_start_tx(port);
tty_wakeup(tty);
}
} else { if (!cts) {
tty->hw_stopped = true;
sdio_uart_stop_tx(port);
}
}
}
tty_kref_put(tty);
}
}
/* * This handles the interrupt from one port.
*/ staticvoid sdio_uart_irq(struct sdio_func *func)
{ struct sdio_uart_port *port = sdio_get_drvdata(func);
u8 iir, lsr;
/* * In a few places sdio_uart_irq() is called directly instead of * waiting for the actual interrupt to be raised and the SDIO IRQ * thread scheduled in order to reduce latency. However, some * interaction with the tty core may end up calling us back * (serial echo, flow control, etc.) through those same places * causing undesirable effects. Let's stop the recursion here.
*/ if (unlikely(port->in_sdio_uart_irq == current)) return;
iir = sdio_in(port, UART_IIR); if (iir & UART_IIR_NO_INT) return;
staticbool uart_carrier_raised(struct tty_port *tport)
{ struct sdio_uart_port *port =
container_of(tport, struct sdio_uart_port, port); unsignedint ret = sdio_uart_claim_func(port); if (ret) /* Missing hardware shouldn't block for carrier */ return 1;
ret = sdio_uart_get_mctrl(port);
sdio_uart_release_func(port);
return ret & TIOCM_CAR;
}
/** * uart_dtr_rts - port helper to set uart signals * @tport: tty port to be updated * @active: set to turn on DTR/RTS * * Called by the tty port helpers when the modem signals need to be * adjusted during an open, close and hangup.
*/
staticvoid uart_dtr_rts(struct tty_port *tport, bool active)
{ struct sdio_uart_port *port =
container_of(tport, struct sdio_uart_port, port); int ret = sdio_uart_claim_func(port); if (ret) return; if (!active)
sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); else
sdio_uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
sdio_uart_release_func(port);
}
/** * sdio_uart_activate - start up hardware * @tport: tty port to activate * @tty: tty bound to this port * * Activate a tty port. The port locking guarantees us this will be * run exactly once per set of opens, and if successful will see the * shutdown method run exactly once to match. Start up and shutdown are * protected from each other by the internal locking and will not run * at the same time even during a hangup event. * * If we successfully start up the port we take an extra kref as we * will keep it around until shutdown when the kref is dropped.
*/
/* * Set the TTY IO error marker - we will only clear this * once we have successfully opened the port.
*/
set_bit(TTY_IO_ERROR, &tty->flags);
kfifo_reset(&port->xmit_fifo);
ret = sdio_uart_claim_func(port); if (ret) return ret;
ret = sdio_enable_func(port->func); if (ret) goto err1;
ret = sdio_claim_irq(port->func, sdio_uart_irq); if (ret) goto err2;
/* * Clear the FIFO buffers and disable them. * (they will be reenabled in sdio_change_speed())
*/
sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO |
UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
sdio_out(port, UART_FCR, 0);
/** * sdio_uart_shutdown - stop hardware * @tport: tty port to shut down * * Deactivate a tty port. The port locking guarantees us this will be * run only if a successful matching activate already ran. The two are * protected from each other by the internal locking and will not run * at the same time even during a hangup event.
*/
/** * sdio_uart_install - install method * @driver: the driver in use (sdio_uart in our case) * @tty: the tty being bound * * Look up and bind the tty and the driver together. Initialize * any needed private data (in our case the termios)
*/
staticint sdio_uart_install(struct tty_driver *driver, struct tty_struct *tty)
{ int idx = tty->index; struct sdio_uart_port *port = sdio_uart_port_get(idx); int ret = tty_standard_install(driver, tty);
if (ret == 0) /* This is the ref sdio_uart_port get provided */
tty->driver_data = port; else
sdio_uart_port_put(port); return ret;
}
/** * sdio_uart_cleanup - called on the last tty kref drop * @tty: the tty being destroyed * * Called asynchronously when the last reference to the tty is dropped. * We cannot destroy the tty->driver_data port kref until this point
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.