public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/1] serial/ns16550: check UART mode for TEMT value
Date: Fri, 21 Dec 2012 20:45:48 -0600	[thread overview]
Message-ID: <1356144348.24276.12@snotra> (raw)
In-Reply-To: <1356081706-31239-1-git-send-email-javier.martinez@collabora.co.uk> (from javier.martinez@collabora.co.uk on Fri Dec 21 03:21:46 2012)

On 12/21/2012 03:21:46 AM, Javier Martinez Canillas wrote:
> On ns16550, the Transmitter Empty (TEMT) Bit is used to
> indicate when the Transmitter Holding Register (THR) and
> the Transmitter Shift Register (TSR) are both empty.
> 
> But ns16550 UART has two operation modes (16450 and FIFO)
> and the TEMT bit logic value set is different on each mode.
> 
> On 16450, the TEMT bit is set to 1 when both THR and TSR are
> empty and is set to 0 on FIFO mode.

When you say "on 16450", do you mean "in 16450 mode"?

> So, checking the TEMT value without checking the current mode
> and assuming a logical value of 1, can lead to U-Boot to hang
> forever if the UART is initialized on FIFO mode by default.

 From the 16550 docs:

   Bit 6 This bit is the Transmitter Empty (TEMT) indicator Bit 6 is set
   to a logic 1 whenever the Transmitter Holding Regis- ter (THR) and  
the
   Transmitter Shift Register (TSR) are both empty It is reset to a  
logic
   0 whenever either the THR or TSR contains a data character In the  
FIFO
   mode this bit is set to one whenever the transmitter FIFO and shift
   register are both empty

Maybe the 16550 implementation you're using is doing something wrong?

> Signed-off-by: Javier Martinez Canillas  
> <javier.martinez@collabora.co.uk>
> ---
>  drivers/serial/ns16550.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
> index bbd91ca..d75d814 100644
> --- a/drivers/serial/ns16550.c
> +++ b/drivers/serial/ns16550.c
> @@ -36,7 +36,9 @@
> 
>  void NS16550_init(NS16550_t com_port, int baud_divisor)
>  {
> -	while (!(serial_in(&com_port->lsr) & UART_LSR_TEMT))
> +	int mode = serial_in(&com_port->fcr) & UART_FCR_FIFO_EN;
> +
> +	while (!(serial_in(&com_port->lsr) & UART_LSR_TEMT ^ mode))
>  		;

Please don't make the reader know the relative prededence of & and ^,  
and
don't use ^ in obfuscatory ways.  It's not even any different from | as
used above -- except that | wouldn't break if TEMT and FIFO_EN had the  
same
value -- so why do you need the exclusive form?

BTW, when I saw the problem that necessitated this, FIFO was enabled, so
this is no better than reverting the patch.

-Scott

  reply	other threads:[~2012-12-22  2:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-21  9:21 [U-Boot] [PATCH 1/1] serial/ns16550: check UART mode for TEMT value Javier Martinez Canillas
2012-12-22  2:45 ` Scott Wood [this message]
2012-12-22  3:40   ` Javier Martinez Canillas
     [not found] <CAAwP0s0y=hPh3FrTSLptd_5UnbYGTV47s=6hVkR8aL0-Z_Ejeg@mail.gmail.com>
2013-01-03  2:58 ` Scott Wood
2013-01-03 21:04   ` Tom Rini
2013-01-07 11:37     ` Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1356144348.24276.12@snotra \
    --to=scottwood@freescale.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox