Skip to content

Commit

Permalink
serial: stm32: update throttle and unthrottle ops for dma mode
Browse files Browse the repository at this point in the history
Disable DMA request line (if enabled) to switch in PIO mode in throttle
ops, so the RX data gets queues into the FIFO. The hardware flow control
is triggered when the RX FIFO is full.

Switch back to DMA mode (re-enable DMA request line) in unthrottle ops.
Hardware flow control is stopped when FIFO is not full anymore.

Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
Signed-off-by: Erwan Le Ray <erwan.leray@foss.st.com>
Link: https://lore.kernel.org/r/20211020150332.10214-4-erwan.leray@foss.st.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Erwan Le Ray authored and Greg Kroah-Hartman committed Oct 21, 2021
1 parent 33bb2f6 commit d1ec8a2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
37 changes: 33 additions & 4 deletions drivers/tty/serial/stm32-usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,12 @@ static irqreturn_t stm32_usart_interrupt(int irq, void *ptr)
* rx errors in dma mode has to be handled ASAP to avoid overrun as the DMA request
* line has been masked by HW and rx data are stacking in FIFO.
*/
if (((sr & USART_SR_RXNE) && !stm32_usart_rx_dma_enabled(port)) ||
((sr & USART_SR_ERR_MASK) && stm32_usart_rx_dma_enabled(port)))
stm32_usart_receive_chars(port, false);
if (!stm32_port->throttled) {
if (((sr & USART_SR_RXNE) && !stm32_usart_rx_dma_enabled(port)) ||
((sr & USART_SR_ERR_MASK) && stm32_usart_rx_dma_enabled(port))) {
stm32_usart_receive_chars(port, false);
}
}

if ((sr & USART_SR_TXE) && !(stm32_port->tx_ch)) {
spin_lock(&port->lock);
Expand All @@ -596,9 +599,11 @@ static irqreturn_t stm32_usart_interrupt(int irq, void *ptr)
static irqreturn_t stm32_usart_threaded_interrupt(int irq, void *ptr)
{
struct uart_port *port = ptr;
struct stm32_port *stm32_port = to_stm32_port(port);

/* Receiver timeout irq for DMA RX */
stm32_usart_receive_chars(port, false);
if (!stm32_port->throttled)
stm32_usart_receive_chars(port, false);

return IRQ_HANDLED;
}
Expand Down Expand Up @@ -711,10 +716,19 @@ static void stm32_usart_throttle(struct uart_port *port)
unsigned long flags;

spin_lock_irqsave(&port->lock, flags);

/*
* Disable DMA request line if enabled, so the RX data gets queued into the FIFO.
* Hardware flow control is triggered when RX FIFO is full.
*/
if (stm32_usart_rx_dma_enabled(port))
stm32_usart_clr_bits(port, ofs->cr3, USART_CR3_DMAR);

stm32_usart_clr_bits(port, ofs->cr1, stm32_port->cr1_irq);
if (stm32_port->cr3_irq)
stm32_usart_clr_bits(port, ofs->cr3, stm32_port->cr3_irq);

stm32_port->throttled = true;
spin_unlock_irqrestore(&port->lock, flags);
}

Expand All @@ -730,6 +744,14 @@ static void stm32_usart_unthrottle(struct uart_port *port)
if (stm32_port->cr3_irq)
stm32_usart_set_bits(port, ofs->cr3, stm32_port->cr3_irq);

/*
* Switch back to DMA mode (re-enable DMA request line).
* Hardware flow control is stopped when FIFO is not full any more.
*/
if (stm32_port->rx_ch)
stm32_usart_set_bits(port, ofs->cr3, USART_CR3_DMAR);

stm32_port->throttled = false;
spin_unlock_irqrestore(&port->lock, flags);
}

Expand Down Expand Up @@ -775,6 +797,13 @@ static int stm32_usart_startup(struct uart_port *port)
if (ofs->rqr != UNDEF_REG)
writel_relaxed(USART_RQR_RXFRQ, port->membase + ofs->rqr);

/*
* DMA request line not re-enabled at resume when port is throttled.
* It will be re-enabled by unthrottle ops.
*/
if (!stm32_port->throttled)
stm32_usart_set_bits(port, ofs->cr3, USART_CR3_DMAR);

/* RX enabling */
val = stm32_port->cr1_irq | USART_CR1_RE | BIT(cfg->uart_enable_bit);
stm32_usart_set_bits(port, ofs->cr1, val);
Expand Down
1 change: 1 addition & 0 deletions drivers/tty/serial/stm32-usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ struct stm32_port {
u32 cr3_irq; /* USART_CR3_RXFTIE */
int last_res;
bool tx_dma_busy; /* dma tx busy */
bool throttled; /* port throttled */
bool hw_flow_control;
bool swap; /* swap RX & TX pins */
bool fifoen;
Expand Down

0 comments on commit d1ec8a2

Please sign in to comment.