On Fri, May 24, 2019 at 1:22 PM Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> wrote: > > On Tue, May 21, 2019 at 04:33:38PM +0530, shubhrajyoti.datta@xxxxxxxxx wrote: > > From: Shubhrajyoti Datta <shubhrajyoti.datta@xxxxxxxxxx> > > > > In case the cable is not connected then the target gets into > > a infinite wait for tx empty. > > Add a timeout to the tx empty wait. > > > > Reported-by: Jean-Francois Dagenais <jeff.dagenais@xxxxxxxxx> > > Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xxxxxxxxxx> > > --- > > drivers/tty/serial/xilinx_uartps.c | 14 ++++++++++---- > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c > > index 8850790..dc86511 100644 > > --- a/drivers/tty/serial/xilinx_uartps.c > > +++ b/drivers/tty/serial/xilinx_uartps.c > > @@ -26,12 +26,14 @@ > > #include <linux/of.h> > > #include <linux/module.h> > > #include <linux/pm_runtime.h> > > +#include <linux/iopoll.h> > > > > #define CDNS_UART_TTY_NAME "ttyPS" > > #define CDNS_UART_NAME "xuartps" > > #define CDNS_UART_MAJOR 0 /* use dynamic node allocation */ > > #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */ > > #define CDNS_UART_REGISTER_SPACE 0x1000 > > +#define TX_TIMEOUT 500000 > > > > /* Rx Trigger level */ > > static int rx_trigger_level = 56; > > @@ -688,14 +690,18 @@ static void cdns_uart_set_termios(struct uart_port *port, > > unsigned int cval = 0; > > unsigned int baud, minbaud, maxbaud; > > unsigned long flags; > > - unsigned int ctrl_reg, mode_reg; > > + unsigned int ctrl_reg, mode_reg, val; > > + int err; > > > > /* Wait for the transmit FIFO to empty before making changes */ > > if (!(readl(port->membase + CDNS_UART_CR) & > > CDNS_UART_CR_TX_DIS)) { > > - while (!(readl(port->membase + CDNS_UART_SR) & > > - CDNS_UART_SR_TXEMPTY)) { > > - cpu_relax(); > > + err = readl_poll_timeout(port->membase + CDNS_UART_SR, > > + val, (val & CDNS_UART_SR_TXEMPTY), > > + 1000, TX_TIMEOUT); > > + if (err) { > > + dev_info(port->dev, "timed out waiting for tx empty"); > > + return; > > Also, shouldn't this be an error? Why not tell the caller something > went wrong? Will do in next version > > thanks, > > greg k-h