// SPDX-License-Identifier: GPL-2.0+ /* * Cadence UART driver (found in Xilinx Zynq) * * Copyright (c) 2011 - 2014 Xilinx, Inc. * * This driver has originally been pushed by Xilinx using a Zynq-branding. This * still shows in the naming of this file, the kconfig symbols and some symbols * in the code.
*/
/* * Mode Register: * The mode register (MR) defines the mode of transfer as well as the data * format. If this register is modified during transmission or reception, * data validity cannot be guaranteed.
*/ #define CDNS_UART_MR_CLKSEL 0x00000001 /* Pre-scalar selection */ #define CDNS_UART_MR_CHMODE_L_LOOP 0x00000200 /* Local loop back mode */ #define CDNS_UART_MR_CHMODE_NORM 0x00000000 /* Normal mode */ #define CDNS_UART_MR_CHMODE_MASK 0x00000300 /* Mask for mode bits */
#define CDNS_UART_MR_PARITY_NONE 0x00000020 /* No parity mode */ #define CDNS_UART_MR_PARITY_MARK 0x00000018 /* Mark parity mode */ #define CDNS_UART_MR_PARITY_SPACE 0x00000010 /* Space parity mode */ #define CDNS_UART_MR_PARITY_ODD 0x00000008 /* Odd parity mode */ #define CDNS_UART_MR_PARITY_EVEN 0x00000000 /* Even parity mode */
#define CDNS_UART_MR_CHARLEN_6_BIT 0x00000006 /* 6 bits data */ #define CDNS_UART_MR_CHARLEN_7_BIT 0x00000004 /* 7 bits data */ #define CDNS_UART_MR_CHARLEN_8_BIT 0x00000000 /* 8 bits data */
/* * Interrupt Registers: * Interrupt control logic uses the interrupt enable register (IER) and the * interrupt disable register (IDR) to set the value of the bits in the * interrupt mask register (IMR). The IMR determines whether to pass an * interrupt to the interrupt status register (ISR). * Writing a 1 to IER Enables an interrupt, writing a 1 to IDR disables an * interrupt. IMR and ISR are read only, and IER and IDR are write only. * Reading either IER or IDR returns 0x00. * All four registers have the same bit definitions.
*/ #define CDNS_UART_IXR_TOUT 0x00000100 /* RX Timeout error interrupt */ #define CDNS_UART_IXR_PARITY 0x00000080 /* Parity error interrupt */ #define CDNS_UART_IXR_FRAMING 0x00000040 /* Framing error interrupt */ #define CDNS_UART_IXR_OVERRUN 0x00000020 /* Overrun error interrupt */ #define CDNS_UART_IXR_TXFULL 0x00000010 /* TX FIFO Full interrupt */ #define CDNS_UART_IXR_TXEMPTY 0x00000008 /* TX FIFO empty interrupt */ #define CDNS_UART_ISR_RXEMPTY 0x00000002 /* RX FIFO empty interrupt */ #define CDNS_UART_IXR_RXTRIG 0x00000001 /* RX FIFO trigger interrupt */ #define CDNS_UART_IXR_RXFULL 0x00000004 /* RX FIFO full interrupt. */ #define CDNS_UART_IXR_RXEMPTY 0x00000002 /* RX FIFO empty interrupt. */ #define CDNS_UART_IXR_RXMASK 0x000021e7 /* Valid RX bit mask */
/* * Do not enable parity error interrupt for the following * reason: When parity error interrupt is enabled, each Rx * parity error always results in 2 events. The first one * being parity error interrupt and the second one with a * proper Rx interrupt with the incoming data. Disabling * parity error interrupt ensures better handling of parity * error events. With this change, for a parity error case, we * get a Rx interrupt with parity error set in ISR register * and we still handle parity errors in the desired way.
*/
/* Goes in read_status_mask for break detection as the HW doesn't do it*/ #define CDNS_UART_IXR_BRK 0x00002000
#define CDNS_UART_RXBS_SUPPORT BIT(1) /* * Modem Control register: * The read/write Modem Control register controls the interface with the modem * or data set, or a peripheral device emulating a modem.
*/ #define CDNS_UART_MODEMCR_FCM 0x00000020 /* Automatic flow control mode */ #define CDNS_UART_MODEMCR_RTS 0x00000002 /* Request to send output control */ #define CDNS_UART_MODEMCR_DTR 0x00000001 /* Data Terminal Ready */
/* * Modem Status register: * The read/write Modem Status register reports the interface with the modem * or data set, or a peripheral device emulating a modem.
*/ #define CDNS_UART_MODEMSR_DCD BIT(7) /* Data Carrier Detect */ #define CDNS_UART_MODEMSR_RI BIT(6) /* Ting Indicator */ #define CDNS_UART_MODEMSR_DSR BIT(5) /* Data Set Ready */ #define CDNS_UART_MODEMSR_CTS BIT(4) /* Clear To Send */
/* * Channel Status Register: * The channel status register (CSR) is provided to enable the control logic * to monitor the status of bits in the channel interrupt status register, * even if these are masked out by the interrupt mask register.
*/ #define CDNS_UART_SR_RXEMPTY 0x00000002 /* RX FIFO empty */ #define CDNS_UART_SR_TXEMPTY 0x00000008 /* TX FIFO empty */ #define CDNS_UART_SR_TXFULL 0x00000010 /* TX FIFO full */ #define CDNS_UART_SR_RXTRIG 0x00000001 /* Rx Trigger */ #define CDNS_UART_SR_TACTIVE 0x00000800 /* TX state machine active */
while ((readl(port->membase + CDNS_UART_SR) &
CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) { if (is_rxbs_support)
rxbs_status = readl(port->membase + CDNS_UART_RXBS);
data = readl(port->membase + CDNS_UART_FIFO);
port->icount.rx++; /* * There is no hardware break detection in Zynq, so we interpret * framing error with all-zeros data as a break sequence. * Most of the time, there's another non-zero byte at the * end of the sequence.
*/ if (!is_rxbs_support && (isrstatus & CDNS_UART_IXR_FRAMING)) { if (!data) {
port->read_status_mask |= CDNS_UART_IXR_BRK;
framerrprocessed = 1; continue;
}
} if (is_rxbs_support && (rxbs_status & CDNS_UART_RXBS_BRK)) {
port->icount.brk++;
status = TTY_BREAK; if (uart_handle_break(port)) continue;
}
if (data &&
(port->read_status_mask & CDNS_UART_IXR_BRK)) {
port->read_status_mask &= ~CDNS_UART_IXR_BRK;
port->icount.brk++; if (uart_handle_break(port)) continue;
}
if (uart_prepare_sysrq_char(port, data)) continue;
if (is_rxbs_support) { if ((rxbs_status & CDNS_UART_RXBS_PARITY)
&& (status_mask & CDNS_UART_IXR_PARITY)) {
port->icount.parity++;
status = TTY_PARITY;
} if ((rxbs_status & CDNS_UART_RXBS_FRAMING)
&& (status_mask & CDNS_UART_IXR_PARITY)) {
port->icount.frame++;
status = TTY_FRAME;
}
} else { if (isrstatus & CDNS_UART_IXR_PARITY) {
port->icount.parity++;
status = TTY_PARITY;
} if ((isrstatus & CDNS_UART_IXR_FRAMING) &&
!framerrprocessed) {
port->icount.frame++;
status = TTY_FRAME;
}
} if (isrstatus & CDNS_UART_IXR_OVERRUN) {
port->icount.overrun++;
tty_insert_flip_char(&port->state->port, 0,
TTY_OVERRUN);
}
tty_insert_flip_char(&port->state->port, data, status);
isrstatus = 0;
}
tty_flip_buffer_push(&port->state->port);
}
/** * cdns_rts_gpio_enable - Configure RTS/GPIO to high/low * @cdns_uart: Handle to the cdns_uart * @enable: Value to be set to RTS/GPIO
*/ staticvoid cdns_rts_gpio_enable(struct cdns_uart *cdns_uart, bool enable)
{
u32 val;
if (cdns_uart->gpiod_rts) {
gpiod_set_value(cdns_uart->gpiod_rts, enable);
} else {
val = readl(cdns_uart->port->membase + CDNS_UART_MODEMCR); if (enable)
val |= CDNS_UART_MODEMCR_RTS; else
val &= ~CDNS_UART_MODEMCR_RTS;
writel(val, cdns_uart->port->membase + CDNS_UART_MODEMCR);
}
}
/** * cdns_rs485_tx_setup - Tx setup specific to rs485 * @cdns_uart: Handle to the cdns_uart
*/ staticvoid cdns_rs485_tx_setup(struct cdns_uart *cdns_uart)
{ bool enable;
/** * cdns_uart_isr - Interrupt handler * @irq: Irq number * @dev_id: Id of the port * * Return: IRQHANDLED
*/ static irqreturn_t cdns_uart_isr(int irq, void *dev_id)
{ struct uart_port *port = (struct uart_port *)dev_id; unsignedint isrstatus;
uart_port_lock(port);
/* Read the interrupt status register to determine which * interrupt(s) is/are active and clear them.
*/
isrstatus = readl(port->membase + CDNS_UART_ISR);
writel(isrstatus, port->membase + CDNS_UART_ISR);
if (isrstatus & CDNS_UART_IXR_TXEMPTY) {
cdns_uart_handle_tx(dev_id);
isrstatus &= ~CDNS_UART_IXR_TXEMPTY;
}
isrstatus &= port->read_status_mask;
isrstatus &= ~port->ignore_status_mask; /* * Skip RX processing if RX is disabled as RXEMPTY will never be set * as read bytes will not be removed from the FIFO.
*/ if (isrstatus & CDNS_UART_IXR_RXMASK &&
!(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_RX_DIS))
cdns_uart_handle_rx(dev_id, isrstatus);
/** * cdns_uart_calc_baud_divs - Calculate baud rate divisors * @clk: UART module input clock * @baud: Desired baud rate * @rbdiv: BDIV value (return value) * @rcd: CD value (return value) * @div8: Value for clk_sel bit in mod (return value) * Return: baud rate, requested baud when possible, or actual baud when there * was too much error, zero if no valid divisors are found. * * Formula to obtain baud rate is * baud_tx/rx rate = clk/CD * (BDIV + 1) * input_clk = (Uart User Defined Clock or Apb Clock) * depends on UCLKEN in MR Reg * clk = input_clk or input_clk/8; * depends on CLKS in MR reg * CD and BDIV depends on values in * baud rate generate register * baud rate clock divisor register
*/ staticunsignedint cdns_uart_calc_baud_divs(unsignedint clk, unsignedint baud, u32 *rbdiv, u32 *rcd, int *div8)
{
u32 cd, bdiv; unsignedint calc_baud; unsignedint bestbaud = 0; unsignedint bauderror; unsignedint besterror = ~0;
if (besterror > bauderror) {
*rbdiv = bdiv;
*rcd = cd;
bestbaud = calc_baud;
besterror = bauderror;
}
} /* use the values when percent error is acceptable */ if (((besterror * 100) / baud) < 3)
bestbaud = baud;
return bestbaud;
}
/** * cdns_uart_set_baud_rate - Calculate and set the baud rate * @port: Handle to the uart port structure * @baud: Baud rate to set * Return: baud rate, requested baud when possible, or actual baud when there * was too much error, zero if no valid divisors are found.
*/ staticunsignedint cdns_uart_set_baud_rate(struct uart_port *port, unsignedint baud)
{ unsignedint calc_baud;
u32 cd = 0, bdiv = 0;
u32 mreg; int div8; struct cdns_uart *cdns_uart = port->private_data;
port = cdns_uart->port; if (port->suspended) return NOTIFY_OK;
switch (event) { case PRE_RATE_CHANGE:
{
u32 bdiv, cd; int div8;
/* * Find out if current baud-rate can be achieved with new clock * frequency.
*/ if (!cdns_uart_calc_baud_divs(ndata->new_rate, cdns_uart->baud,
&bdiv, &cd, &div8)) {
dev_warn(port->dev, "clock rate change rejected\n"); return NOTIFY_BAD;
}
uart_port_lock_irqsave(cdns_uart->port, &flags);
/* Disable the TX and RX to set baud rate */
ctrl_reg = readl(port->membase + CDNS_UART_CR);
ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS;
writel(ctrl_reg, port->membase + CDNS_UART_CR);
while (readl(port->membase + CDNS_UART_CR) &
(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
cpu_relax();
/* * Clear the RX disable and TX disable bits and then set the TX * enable bit and RX enable bit to enable the transmitter and * receiver.
*/
writel(rx_timeout, port->membase + CDNS_UART_RXTOUT);
ctrl_reg = readl(port->membase + CDNS_UART_CR);
ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS);
ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN;
writel(ctrl_reg, port->membase + CDNS_UART_CR);
/** * cdns_uart_start_tx - Start transmitting bytes * @port: Handle to the uart port structure
*/ staticvoid cdns_uart_start_tx(struct uart_port *port)
{ unsignedint status; struct cdns_uart *cdns_uart = port->private_data;
if (uart_tx_stopped(port)) return;
/* * Set the TX enable bit and clear the TX disable bit to enable the * transmitter.
*/
status = readl(port->membase + CDNS_UART_CR);
status &= ~CDNS_UART_CR_TX_DIS;
status |= CDNS_UART_CR_TX_EN;
writel(status, port->membase + CDNS_UART_CR);
if (kfifo_is_empty(&port->state->port.xmit_fifo)) return;
/** * cdns_uart_break_ctl - Based on the input ctl we have to start or stop * transmitting char breaks * @port: Handle to the uart port structure * @ctl: Value based on which start or stop decision is taken
*/ staticvoid cdns_uart_break_ctl(struct uart_port *port, int ctl)
{ unsignedint status; unsignedlong flags;
/** * cdns_uart_set_termios - termios operations, handling data length, parity, * stop bits, flow control, baud rate * @port: Handle to the uart port structure * @termios: Handle to the input termios structure * @old: Values of the previously saved termios structure
*/ staticvoid cdns_uart_set_termios(struct uart_port *port, struct ktermios *termios, conststruct ktermios *old)
{
u32 cval = 0; unsignedint baud, minbaud, maxbaud; unsignedlong flags; unsignedint ctrl_reg, mode_reg;
uart_port_lock_irqsave(port, &flags);
/* Disable the TX and RX to set baud rate */
ctrl_reg = readl(port->membase + CDNS_UART_CR);
ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS;
writel(ctrl_reg, port->membase + CDNS_UART_CR);
/* * Min baud rate = 6bps and Max Baud Rate is 10Mbps for 100Mhz clk * min and max baud should be calculated here based on port->uartclk. * this way we get a valid baud and can safely call set_baud()
*/
minbaud = port->uartclk /
((CDNS_UART_BDIV_MAX + 1) * CDNS_UART_CD_MAX * 8);
maxbaud = port->uartclk / (CDNS_UART_BDIV_MIN + 1);
baud = uart_get_baud_rate(port, termios, old, minbaud, maxbaud);
baud = cdns_uart_set_baud_rate(port, baud); if (tty_termios_baud_rate(termios))
tty_termios_encode_baud_rate(termios, baud, baud);
/* Update the per-port timeout. */
uart_update_timeout(port, termios->c_cflag, baud);
while (readl(port->membase + CDNS_UART_CR) &
(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
cpu_relax();
/* * Clear the RX disable and TX disable bits and then set the TX enable * bit and RX enable bit to enable the transmitter and receiver.
*/
ctrl_reg = readl(port->membase + CDNS_UART_CR);
ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS);
ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN;
writel(ctrl_reg, port->membase + CDNS_UART_CR);
/* ignore all characters if CREAD is not set */ if ((termios->c_cflag & CREAD) == 0)
port->ignore_status_mask |= CDNS_UART_IXR_RXTRIG |
CDNS_UART_IXR_TOUT | CDNS_UART_IXR_PARITY |
CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN;
mode_reg = readl(port->membase + CDNS_UART_MR);
/* Handling Data Size */ switch (termios->c_cflag & CSIZE) { case CS6:
cval |= CDNS_UART_MR_CHARLEN_6_BIT; break; case CS7:
cval |= CDNS_UART_MR_CHARLEN_7_BIT; break; default: case CS8:
cval |= CDNS_UART_MR_CHARLEN_8_BIT;
termios->c_cflag &= ~CSIZE;
termios->c_cflag |= CS8; break;
}
/* Handling Parity and Stop Bits length */ if (termios->c_cflag & CSTOPB)
cval |= CDNS_UART_MR_STOPMODE_2_BIT; /* 2 STOP bits */ else
cval |= CDNS_UART_MR_STOPMODE_1_BIT; /* 1 STOP bit */
if (termios->c_cflag & PARENB) { /* Mark or Space parity */ if (termios->c_cflag & CMSPAR) { if (termios->c_cflag & PARODD)
cval |= CDNS_UART_MR_PARITY_MARK; else
cval |= CDNS_UART_MR_PARITY_SPACE;
} else { if (termios->c_cflag & PARODD)
cval |= CDNS_UART_MR_PARITY_ODD; else
cval |= CDNS_UART_MR_PARITY_EVEN;
}
} else {
cval |= CDNS_UART_MR_PARITY_NONE;
}
cval |= mode_reg & 1;
writel(cval, port->membase + CDNS_UART_MR);
/** * cdns_uart_startup - Called when an application opens a cdns_uart port * @port: Handle to the uart port structure * * Return: 0 on success, negative errno otherwise
*/ staticint cdns_uart_startup(struct uart_port *port)
{ struct cdns_uart *cdns_uart = port->private_data; bool is_brk_support; int ret; unsignedlong flags; unsignedint status = 0;
ret = reset_control_deassert(cdns_uart->rstc); if (ret) return ret;
uart_port_lock_irqsave(port, &flags);
/* Disable the TX and RX */
writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS,
port->membase + CDNS_UART_CR);
/* Set the Control Register with TX/RX Enable, TX/RX Reset, * no break chars.
*/
writel(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST,
port->membase + CDNS_UART_CR);
while (readl(port->membase + CDNS_UART_CR) &
(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST))
cpu_relax();
if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED)
cdns_rs485_rx_setup(cdns_uart);
/* * Clear the RX disable bit and then set the RX enable bit to enable * the receiver.
*/
status = readl(port->membase + CDNS_UART_CR);
status &= ~CDNS_UART_CR_RX_DIS;
status |= CDNS_UART_CR_RX_EN;
writel(status, port->membase + CDNS_UART_CR);
/* Set the Mode Register with normal mode,8 data bits,1 stop bit, * no parity.
*/
writel(CDNS_UART_MR_CHMODE_NORM | CDNS_UART_MR_STOPMODE_1_BIT
| CDNS_UART_MR_PARITY_NONE | CDNS_UART_MR_CHARLEN_8_BIT,
port->membase + CDNS_UART_MR);
/* * Set the RX FIFO Trigger level to use most of the FIFO, but it * can be tuned with a module parameter
*/
writel(rx_trigger_level, port->membase + CDNS_UART_RXWM);
/* * Receive Timeout register is enabled but it * can be tuned with a module parameter
*/
writel(rx_timeout, port->membase + CDNS_UART_RXTOUT);
/* Clear out any pending interrupts before enabling them */
writel(readl(port->membase + CDNS_UART_ISR),
port->membase + CDNS_UART_ISR);
uart_port_unlock_irqrestore(port, flags);
ret = request_irq(port->irq, cdns_uart_isr, 0, CDNS_UART_NAME, port); if (ret) {
dev_err(port->dev, "request_irq '%d' failed with %d\n",
port->irq, ret); return ret;
}
/* Set the Interrupt Registers with desired interrupts */ if (is_brk_support)
writel(CDNS_UART_RX_IRQS | CDNS_UART_IXR_BRK,
port->membase + CDNS_UART_IER); else
writel(CDNS_UART_RX_IRQS, port->membase + CDNS_UART_IER);
return 0;
}
/** * cdns_uart_shutdown - Called when an application closes a cdns_uart port * @port: Handle to the uart port structure
*/ staticvoid cdns_uart_shutdown(struct uart_port *port)
{ int status; unsignedlong flags; struct cdns_uart *cdns_uart = port->private_data;
if (cdns_uart->port->rs485.flags & SER_RS485_ENABLED)
hrtimer_cancel(&cdns_uart->tx_timer);
/* Disable the TX and RX */
writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS,
port->membase + CDNS_UART_CR);
uart_port_unlock_irqrestore(port, flags);
free_irq(port->irq, port);
}
/** * cdns_uart_type - Set UART type to cdns_uart port * @port: Handle to the uart port structure * * Return: string on success, NULL otherwise
*/ staticconstchar *cdns_uart_type(struct uart_port *port)
{ return port->type == PORT_XUARTPS ? CDNS_UART_NAME : NULL;
}
/** * cdns_uart_verify_port - Verify the port params * @port: Handle to the uart port structure * @ser: Handle to the structure whose members are compared * * Return: 0 on success, negative errno otherwise.
*/ staticint cdns_uart_verify_port(struct uart_port *port, struct serial_struct *ser)
{ if (ser->type != PORT_UNKNOWN && ser->type != PORT_XUARTPS) return -EINVAL; if (port->irq != ser->irq) return -EINVAL; if (ser->io_type != UPIO_MEM) return -EINVAL; if (port->iobase != ser->port) return -EINVAL; if (ser->hub6 != 0) return -EINVAL; return 0;
}
/** * cdns_uart_request_port - Claim the memory region attached to cdns_uart port, * called when the driver adds a cdns_uart port via * uart_add_one_port() * @port: Handle to the uart port structure * * Return: 0 on success, negative errno otherwise.
*/ staticint cdns_uart_request_port(struct uart_port *port)
{ if (!request_mem_region(port->mapbase, port->mapsize,
CDNS_UART_NAME)) { return -ENOMEM;
}
port->membase = ioremap(port->mapbase, port->mapsize); if (!port->membase) {
dev_err(port->dev, "Unable to map registers\n");
release_mem_region(port->mapbase, port->mapsize); return -ENOMEM;
} return 0;
}
/** * cdns_uart_release_port - Release UART port * @port: Handle to the uart port structure * * Release the memory region attached to a cdns_uart port. Called when the * driver removes a cdns_uart port via uart_remove_one_port().
*/ staticvoid cdns_uart_release_port(struct uart_port *port)
{
release_mem_region(port->mapbase, port->mapsize);
iounmap(port->membase);
port->membase = NULL;
}
/** * cdns_uart_config_port - Configure UART port * @port: Handle to the uart port structure * @flags: If any
*/ staticvoid cdns_uart_config_port(struct uart_port *port, int flags)
{ if (flags & UART_CONFIG_TYPE && cdns_uart_request_port(port) == 0)
port->type = PORT_XUARTPS;
}
/** * cdns_uart_get_mctrl - Get the modem control state * @port: Handle to the uart port structure * * Return: the modem control state
*/ staticunsignedint cdns_uart_get_mctrl(struct uart_port *port)
{
u32 val; unsignedint mctrl = 0; struct cdns_uart *cdns_uart_data = port->private_data;
if (cdns_uart_data->cts_override) return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
val = readl(port->membase + CDNS_UART_MODEMSR); if (val & CDNS_UART_MODEMSR_CTS)
mctrl |= TIOCM_CTS; if (val & CDNS_UART_MODEMSR_DSR)
mctrl |= TIOCM_DSR; if (val & CDNS_UART_MODEMSR_RI)
mctrl |= TIOCM_RNG; if (val & CDNS_UART_MODEMSR_DCD)
mctrl |= TIOCM_CAR;
/* Check if FIFO is empty */ if (readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_RXEMPTY)
c = NO_POLL_CHAR; else/* Read a character */
c = (unsignedchar) readl(port->membase + CDNS_UART_FIFO);
uart_port_unlock_irqrestore(port, flags);
return c;
}
staticvoid cdns_uart_poll_put_char(struct uart_port *port, unsignedchar c)
{ unsignedlong flags;
uart_port_lock_irqsave(port, &flags);
/* Wait until FIFO is empty */ while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXEMPTY))
cpu_relax();
/* Write a character */
writel(c, port->membase + CDNS_UART_FIFO);
/* Wait until FIFO is empty */ while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXEMPTY))
cpu_relax();
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE /** * cdns_uart_console_putchar - write the character to the FIFO buffer * @port: Handle to the uart port structure * @ch: Character to be written
*/ staticvoid cdns_uart_console_putchar(struct uart_port *port, unsignedchar ch)
{ unsignedint ctrl_reg; unsignedlong timeout;
timeout = jiffies + msecs_to_jiffies(1000); while (1) {
ctrl_reg = readl(port->membase + CDNS_UART_CR); if (!(ctrl_reg & CDNS_UART_CR_TX_DIS)) break; if (time_after(jiffies, timeout)) {
dev_warn(port->dev, "timeout waiting for Enable\n"); return;
}
cpu_relax();
}
/* initialise control register */
writel(CDNS_UART_CR_TX_EN|CDNS_UART_CR_TXRST|CDNS_UART_CR_RXRST,
port->membase + CDNS_UART_CR);
/* only set baud if specified on command line - otherwise * assume it has been initialized by a boot loader.
*/ if (port->uartclk && device->baud) {
u32 cd = 0, bdiv = 0;
u32 mr; int div8;
/* Static pointer to console port */ staticstruct uart_port *console_port;
/** * cdns_uart_console_write - perform write operation * @co: Console handle * @s: Pointer to character array * @count: No of characters
*/ staticvoid cdns_uart_console_write(struct console *co, constchar *s, unsignedint count)
{ struct uart_port *port = console_port; unsignedlong flags; unsignedint imr, ctrl; int locked = 1;
if (oops_in_progress)
locked = uart_port_trylock_irqsave(port, &flags); else
uart_port_lock_irqsave(port, &flags);
/* save and disable interrupt */
imr = readl(port->membase + CDNS_UART_IMR);
writel(imr, port->membase + CDNS_UART_IDR);
/* * Make sure that the tx part is enabled. Set the TX enable bit and * clear the TX disable bit to enable the transmitter.
*/
ctrl = readl(port->membase + CDNS_UART_CR);
ctrl &= ~CDNS_UART_CR_TX_DIS;
ctrl |= CDNS_UART_CR_TX_EN;
writel(ctrl, port->membase + CDNS_UART_CR);
uart_console_write(port, s, count, cdns_uart_console_putchar); while (cdns_uart_tx_empty(port) != TIOCSER_TEMT)
cpu_relax();
/* restore interrupt state */
writel(imr, port->membase + CDNS_UART_IER);
if (locked)
uart_port_unlock_irqrestore(port, flags);
}
/* Temporary variable for storing number of instances */ staticint instances;
/** * cdns_rs485_config - Called when an application calls TIOCSRS485 ioctl. * @port: Pointer to the uart_port structure * @termios: Pointer to the ktermios structure * @rs485: Pointer to the serial_rs485 structure * * Return: 0
*/ staticint cdns_rs485_config(struct uart_port *port, struct ktermios *termios, struct serial_rs485 *rs485)
{
u32 val; struct cdns_uart *cdns_uart = port->private_data;
if (rs485->flags & SER_RS485_ENABLED) {
dev_dbg(port->dev, "Setting UART to RS485\n"); /* Make sure auto RTS is disabled */
val = readl(port->membase + CDNS_UART_MODEMCR);
val &= ~CDNS_UART_MODEMCR_FCM;
writel(val, port->membase + CDNS_UART_MODEMCR);
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE /* * If console hasn't been found yet try to assign this port * because it is required to be assigned for console setup function. * If register_console() don't assign value, then console_port pointer * is cleanup.
*/ if (!console_port) {
cdns_uart_console.index = id;
console_port = port;
} #endif if (cdns_uart_data->port->rs485.flags & SER_RS485_ENABLED)
cdns_rs485_rx_setup(cdns_uart_data);
#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE /* This is not port which is used for console that's why clean it up */ if (console_port == port &&
!console_is_registered(cdns_uart_uart_driver.cons)) {
console_port = NULL;
cdns_uart_console.index = -1;
} #endif
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.