Skip to content

Commit

Permalink
Add 16550_WAIT_LCR to Kconfig. Tested OK
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Aug 2, 2023
1 parent 2464d7a commit 7ee02d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CONFIG_16550_UART0_CLOCK=23040000
CONFIG_16550_UART0_IRQ=57
CONFIG_16550_UART0_SERIAL_CONSOLE=y
CONFIG_16550_UART=y
CONFIG_16550_WAIT_LCR=y
CONFIG_ARCH="risc-v"
CONFIG_ARCH_ADDRENV=y
CONFIG_ARCH_BOARD="rv-virt"
Expand Down
9 changes: 9 additions & 0 deletions drivers/serial/Kconfig-16550
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,13 @@ config 16550_ADDRWIDTH
Default: 8
Note: 0 means auto detect address size (uintptr_t)

config 16550_WAIT_LCR
bool "Wait for UART before setting LCR"
default n
---help---
Before setting the Line Control Register (LCR), wait until UART is
not busy. This is required for Synopsys DesignWare 8250, which
will trigger spurious interrupts when setting the LCR without
waiting. Default: n

endif # 16550_UART
15 changes: 8 additions & 7 deletions drivers/serial/uart_16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,7 @@ static inline void u16550_serialout(FAR struct u16550_s *priv, int offset,
#endif
}

#define CONFIG_16550_SERIAL_WAIT_LCR //// TODO: JH7110 must wait till UART is not busy before setting LCR
#ifdef CONFIG_16550_SERIAL_WAIT_LCR
#ifdef CONFIG_16550_WAIT_LCR
/***************************************************************************
* Name: u16550_wait
*
Expand Down Expand Up @@ -666,7 +665,7 @@ static int u16550_wait(FAR struct u16550_s *priv)
_err("UART timeout\n");
return ERROR;
}
#endif /* CONFIG_16550_SERIAL_WAIT_LCR */
#endif /* CONFIG_16550_WAIT_LCR */

/****************************************************************************
* Name: u16550_disableuartint
Expand Down Expand Up @@ -713,14 +712,14 @@ static inline void u16550_enablebreaks(FAR struct u16550_s *priv,
lcr &= ~UART_LCR_BRK;
}

#ifdef CONFIG_16550_SERIAL_WAIT_LCR
#ifdef CONFIG_16550_WAIT_LCR
/* Wait till UART is not busy before setting LCR */

if (u16550_wait(priv) < 0)
{
_err("UART wait failed\n");
}
#endif /* CONFIG_16550_SERIAL_WAIT_LCR */
#endif /* CONFIG_16550_WAIT_LCR */

u16550_serialout(priv, UART_LCR_OFFSET, lcr);
}
Expand Down Expand Up @@ -816,15 +815,15 @@ static int u16550_setup(FAR struct uart_dev_s *dev)
lcr |= (UART_LCR_PEN | UART_LCR_EPS);
}

#ifdef CONFIG_16550_SERIAL_WAIT_LCR
#ifdef CONFIG_16550_WAIT_LCR
/* Wait till UART is not busy before setting LCR */

if (u16550_wait(priv) < 0)
{
_err("UART wait failed\n");
return ERROR;
}
#endif /* CONFIG_16550_SERIAL_WAIT_LCR */
#endif /* CONFIG_16550_WAIT_LCR */

/* Enter DLAB=1 */

Expand All @@ -836,13 +835,15 @@ static int u16550_setup(FAR struct uart_dev_s *dev)
u16550_serialout(priv, UART_DLM_OFFSET, div >> 8);
u16550_serialout(priv, UART_DLL_OFFSET, div & 0xff);

#ifdef CONFIG_16550_WAIT_LCR
/* Wait till UART is not busy before setting LCR */

if (u16550_wait(priv) < 0)
{
_err("UART wait failed\n");
return ERROR;
}
#endif /* CONFIG_16550_WAIT_LCR */

/* Clear DLAB */

Expand Down

0 comments on commit 7ee02d6

Please sign in to comment.