Patchwork [U-Boot] AT91: Small fix on AT91 USART initialization code

login
register
mail settings
Submitter Xu, Hong
Date Aug. 1, 2011, 9:01 a.m.
Message ID <1312189274-28422-1-git-send-email-hong.xu@atmel.com>
Download mbox | patch
Permalink /patch/107693/
State Superseded
Delegated to: Reinhard Meyer
Headers show

Comments

Xu, Hong - Aug. 1, 2011, 9:01 a.m.
Before reset dbgu transmitter, we just wait TXEMPTY to drain the
transmitter register. If not doing this, we may sometimes see several
weird characters from DBGU.

A short delay is also added to make sure the new serial settings are
settled.

Signed-off-by: Hong Xu <hong.xu@atmel.com>
---
 drivers/serial/atmel_usart.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
Reinhard Meyer - Aug. 1, 2011, 11:08 a.m.
Dear Hong Xu,
> Before reset dbgu transmitter, we just wait TXEMPTY to drain the
> transmitter register. If not doing this, we may sometimes see several
> weird characters from DBGU.
>
> A short delay is also added to make sure the new serial settings are
> settled.
>
> Signed-off-by: Hong Xu<hong.xu@atmel.com>
> ---
>   drivers/serial/atmel_usart.c |    8 +++++++-
>   1 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/serial/atmel_usart.c b/drivers/serial/atmel_usart.c
> index e326b2b..0d5d254 100644
> --- a/drivers/serial/atmel_usart.c
> +++ b/drivers/serial/atmel_usart.c
> @@ -49,17 +49,23 @@ int serial_init(void)
>   {
>   	atmel_usart3_t *usart = (atmel_usart3_t *)CONFIG_USART_BASE;
>
> +	/* Just in case: drain transmitter register */
> +	while (!(readl(&usart->csr)&  USART3_BIT(TXEMPTY)))
> +		;

Are you sure-sure that can never hang, for example if the USART was never
initialized or when the baudrate generator is not running?
Can you rule out situations where TXREMPTY might not set because of
previous states?
Imagine NOR boot (or the 9XE) where not at91bootstrap might have run before?

> +
>   	writel(USART3_BIT(RSTRX) | USART3_BIT(RSTTX),&usart->cr);
>
>   	serial_setbrg();
>
> -	writel(USART3_BIT(RXEN) | USART3_BIT(TXEN),&usart->cr);
>   	writel((USART3_BF(USART_MODE, USART3_USART_MODE_NORMAL)
>   			   | USART3_BF(USCLKS, USART3_USCLKS_MCK)
>   			   | USART3_BF(CHRL, USART3_CHRL_8)
>   			   | USART3_BF(PAR, USART3_PAR_NONE)
>   			   | USART3_BF(NBSTOP, USART3_NBSTOP_1)),
>   			&usart->mr);
> +	writel(USART3_BIT(RXEN) | USART3_BIT(TXEN),&usart->cr);
> +	/* __udelay(100) is enough for the new settings to be settled */
> +	__udelay(100);

Not to be picky here, but "100us is enough for ..." reads nicer in
the commentary:)

Best Regards,
Reinhard

Patch

diff --git a/drivers/serial/atmel_usart.c b/drivers/serial/atmel_usart.c
index e326b2b..0d5d254 100644
--- a/drivers/serial/atmel_usart.c
+++ b/drivers/serial/atmel_usart.c
@@ -49,17 +49,23 @@  int serial_init(void)
 {
 	atmel_usart3_t *usart = (atmel_usart3_t *)CONFIG_USART_BASE;
 
+	/* Just in case: drain transmitter register */
+	while (!(readl(&usart->csr) & USART3_BIT(TXEMPTY)))
+		;
+
 	writel(USART3_BIT(RSTRX) | USART3_BIT(RSTTX), &usart->cr);
 
 	serial_setbrg();
 
-	writel(USART3_BIT(RXEN) | USART3_BIT(TXEN), &usart->cr);
 	writel((USART3_BF(USART_MODE, USART3_USART_MODE_NORMAL)
 			   | USART3_BF(USCLKS, USART3_USCLKS_MCK)
 			   | USART3_BF(CHRL, USART3_CHRL_8)
 			   | USART3_BF(PAR, USART3_PAR_NONE)
 			   | USART3_BF(NBSTOP, USART3_NBSTOP_1)),
 			   &usart->mr);
+	writel(USART3_BIT(RXEN) | USART3_BIT(TXEN), &usart->cr);
+	/* __udelay(100) is enough for the new settings to be settled */
+	__udelay(100);
 
 	return 0;
 }