All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] nios2: convert altera_uart to driver model
Date: Fri, 18 Sep 2015 05:29:12 +0200	[thread overview]
Message-ID: <201509180529.12773.marex@denx.de> (raw)
In-Reply-To: <1442546658-26012-1-git-send-email-thomas@wytron.com.tw>

On Friday, September 18, 2015 at 05:24:18 AM, Thomas Chou wrote:
> Convert altera_uart to driver model.
> 
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---

Hi!

minor nitpicks below :)

> -typedef volatile struct {
> +struct altera_uart_regs {
>  	unsigned	rxdata;		/* Rx data reg */
>  	unsigned	txdata;		/* Tx data reg */
>  	unsigned	status;		/* Status reg */
>  	unsigned	control;	/* Control reg */
>  	unsigned	divisor;	/* Baud rate divisor reg */
>  	unsigned	endofpacket;	/* End-of-packet reg */

Probably make this u32 instead of unsigned, so we're in the safe.

> -} nios_uart_t;
> +};

[...]

> -static int altera_serial_init(void)
> +static int altera_uart_putc(struct udevice *dev, const char c)
>  {
> -	return 0;
> -}
> +	struct altera_uart_platdata *plat = dev->platdata;
> +	struct altera_uart_regs *const regs = plat->reg;
> 
> -#else
> +	if (!(readl(&regs->status) & NIOS_UART_TRDY))
> +		return -EAGAIN;
> 
> -static void altera_serial_setbrg(void)
> -{
> -	unsigned div;
> +	writel((unsigned char)c, &regs->txdata);

Is this type-cast needed ?

> -	div = (CONFIG_SYS_CLK_FREQ/gd->baudrate)-1;
> -	writel (div, &uart->divisor);
> +	return 0;
>  }
> 
> -static int altera_serial_init(void)
> +static int altera_uart_pending(struct udevice *dev, bool input)
>  {
> -	serial_setbrg();
> -	return 0;
> +	struct altera_uart_platdata *plat = dev->platdata;
> +	struct altera_uart_regs *const regs = plat->reg;
> +	unsigned st = readl(&regs->status);
> +
> +	if (input)
> +		return (st & NIOS_UART_RRDY) ? 1 : 0;
> +	else
> +		return (st & NIOS_UART_TMT) ? 0 : 1;

Drop the ternary please, just use return st & flag or return !(st & flag),
it's not necessary to return 0 or 1, you can safely return 0 or non-zero.

>  }
> 
> -#endif /* CONFIG_SYS_NIOS_FIXEDBAUD */
> -
> -/*-----------------------------------------------------------------------
> - * UART CONSOLE
> - *---------------------------------------------------------------------*/
> -static void altera_serial_putc(char c)
> +static int altera_uart_getc(struct udevice *dev)
>  {
> -	if (c == '\n')
> -		serial_putc ('\r');
> -	while ((readl (&uart->status) & NIOS_UART_TRDY) == 0)
> -		WATCHDOG_RESET ();
> -	writel ((unsigned char)c, &uart->txdata);
> +	struct altera_uart_platdata *plat = dev->platdata;
> +	struct altera_uart_regs *const regs = plat->reg;
> +
> +	if (readl(&regs->status) & NIOS_UART_RRDY)
> +		return (readl(&regs->rxdata) & 0xff);

Parenthesis not needed around the readl(...) & 0xff expression.

> +	else
> +		return -EAGAIN;
>  }

[...]

Thanks!

  reply	other threads:[~2015-09-18  3:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-18  3:24 [U-Boot] [PATCH] nios2: convert altera_uart to driver model Thomas Chou
2015-09-18  3:29 ` Marek Vasut [this message]
2015-09-18  4:04   ` Simon Glass
2015-09-18  6:08 ` [U-Boot] [PATCH v2] " Thomas Chou
2015-09-18 14:54   ` Marek Vasut
2015-09-20 11:41 ` [U-Boot] [PATCH v3] " Thomas Chou
2015-09-24  6:58   ` Thomas Chou

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=201509180529.12773.marex@denx.de \
    --to=marex@denx.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.