public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: York Sun <yorksun@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 13/16] serial: lpuart: add 32-bit registers lpuart support
Date: Wed, 20 Aug 2014 10:23:34 -0700	[thread overview]
Message-ID: <53F4D996.5060505@freescale.com> (raw)
In-Reply-To: <1408416905-19771-14-git-send-email-b18965@freescale.com>

On 08/18/2014 07:55 PM, Alison Wang wrote:
> From: Jingchang Lu <jingchang.lu@freescale.com>
> 
> On vybrid, lpuart's registers are 8-bit. On LS102xA, lpuart's registers
> are 32-bit. This patch adds the support for 32-bit registers on
> LS102xA.
> 
> Signed-off-by: Jingchang Lu <jingchang.lu@freescale.com>
> Signed-off-by: Yuan Yao <yao.yuan@freescale.com>
> ---
> Change log:
>  v5: No change.
>  v4: Add commit messages.
>  v3: New file.
> 
>  drivers/serial/serial_lpuart.c | 122 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 122 insertions(+)
> 
> diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
> index da5f9a2..6e639b7 100644
> --- a/drivers/serial/serial_lpuart.c
> +++ b/drivers/serial/serial_lpuart.c
> @@ -17,10 +17,34 @@
>  #define UC2_TE          (1 << 3)
>  #define UC2_RE          (1 << 2)
>  
> +#define STAT_LBKDIF	(1 << 31)
> +#define STAT_RXEDGIF	(1 << 30)
> +#define STAT_TDRE	(1 << 23)
> +#define STAT_RDRF	(1 << 21)
> +#define STAT_IDLE	(1 << 20)
> +#define STAT_OR		(1 << 19)
> +#define STAT_NF		(1 << 18)
> +#define STAT_FE		(1 << 17)
> +#define STAT_PF		(1 << 16)
> +#define STAT_MA1F	(1 << 15)
> +#define STAT_MA2F	(1 << 14)
> +#define STAT_FLAGS	(STAT_LBKDIF | STAT_RXEDGIF | STAT_IDLE | STAT_OR | \
> +			STAT_NF | STAT_FE | STAT_PF | STAT_MA1F | STAT_MA2F)
> +
> +#define CTRL_TE		(1 << 19)
> +#define CTRL_RE		(1 << 18)
> +
> +#define FIFO_TXFE		0x80
> +#define FIFO_RXFE		0x40
> +
> +#define WATER_TXWATER_OFF	1
> +#define WATER_RXWATER_OFF	16
> +
>  DECLARE_GLOBAL_DATA_PTR;
>  
>  struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
>  
> +#ifndef CONFIG_LPUART_32B_REG
>  static void lpuart_serial_setbrg(void)
>  {
>  	u32 clk = mxc_get_clock(MXC_UART_CLK);
> @@ -107,13 +131,111 @@ static struct serial_device lpuart_serial_drv = {
>  	.getc = lpuart_serial_getc,
>  	.tstc = lpuart_serial_tstc,
>  };
> +#else
> +static void lpuart32_serial_setbrg(void)
> +{
> +	u32 clk = CONFIG_SYS_CLK_FREQ;
> +	u32 sbr;
> +
> +	if (!gd->baudrate)
> +		gd->baudrate = CONFIG_BAUDRATE;
> +
> +	sbr = (clk / (16 * gd->baudrate));
> +	/* place adjustment later - n/32 BRFA */
> +
> +	out_be32(&base->baud, sbr);
> +}
> +
> +static int lpuart32_serial_getc(void)
> +{
> +	u32 stat;
> +
> +	while (((stat = in_be32(&base->stat)) & STAT_RDRF) == 0) {
> +		out_be32(&base->stat, STAT_FLAGS);
> +		WATCHDOG_RESET();
> +	}
> +
> +	return in_be32(&base->data) & 0x3ff;
> +}
> +
> +static void lpuart32_serial_putc(const char c)
> +{
> +	if (c == '\n')
> +		serial_putc('\r');
> +
> +	while (!(in_be32(&base->stat) & STAT_TDRE))
> +		WATCHDOG_RESET();
> +
> +	out_be32(&base->data, c);
> +}
> +
> +/*
> + * Test whether a character is in the RX buffer
> + */
> +static int lpuart32_serial_tstc(void)
> +{
> +	if ((in_be32(&base->water) >> 24) == 0)
> +		return 0;
> +
> +	return 1;
> +}
> +
> +/*
> + * Initialise the serial port with the given baudrate. The settings
> + * are always 8 data bits, no parity, 1 stop bit, no start bits.
> + */
> +static int lpuart32_serial_init(void)
> +{
> +	u8 ctrl;
> +
> +	ctrl = in_be32(&base->ctrl);
> +	ctrl &= ~CTRL_RE;
> +	ctrl &= ~CTRL_TE;
> +	out_be32(&base->ctrl, ctrl);
> +
> +	out_be32(&base->modir, 0);
> +	out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE));
> +
> +	out_be32(&base->match, 0);
> +	/* provide data bits, parity, stop bit, etc */
> +
> +	serial_setbrg();
> +
> +	out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
> +
> +	return 0;
> +}
> +
> +static struct serial_device lpuart32_serial_drv = {
> +	.name = "lpuart32_serial",
> +	.start = lpuart32_serial_init,
> +	.stop = NULL,
> +	.setbrg = lpuart32_serial_setbrg,
> +	.putc = lpuart32_serial_putc,
> +	.puts = default_serial_puts,
> +	.getc = lpuart32_serial_getc,
> +	.tstc = lpuart32_serial_tstc,
> +};
> +#endif
> +void lpuart32_serial_initialize(void)
> +{
> +	serial_register(&lpuart32_serial_drv);
> +}

This breaks any board without CONFIG_LPUART_32B_REG defined, for example
vf610twr. Please fix.

York

  reply	other threads:[~2014-08-20 17:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-19  2:54 [U-Boot] [PATCH v5 0/16] arm: ls102xa: Add Freescale LS102xA SoC and LS1021AQDS/TWR board support Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 01/16] arm: ls102xa: Add Freescale LS102xA SoC support Alison Wang
2014-08-19 11:19   ` Mark Rutland
2014-08-20  2:39     ` AlisonWang
2014-08-20  9:38       ` Mark Rutland
2014-08-19  2:54 ` [U-Boot] [PATCH v5 02/16] ls102xa: i2c: Add i2c support for LS102xA Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 03/16] net: Merge asm/fsl_enet.h into fsl_mdio.h Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 04/16] net: mdio: Use mb() to be compatible for both ARM and PowerPC Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 05/16] ls102xa: etsec: Add etsec support for LS102xA Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 06/16] ls102xa: esdhc: Add esdhc " Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 07/16] driver/ddr/freescale: Add support of accumulate ECC Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 08/16] driver/ddr/freescale: Fix DDR3 driver for ARM Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 09/16] driver/ddr/fsl: Add support of overriding chip select write leveling Alison Wang
2014-08-19  2:54 ` [U-Boot] [PATCH v5 10/16] arm: ls102xa: Add basic support for LS1021AQDS board Alison Wang
2014-08-19  2:55 ` [U-Boot] [PATCH v5 11/16] arm: ls102xa: Add basic support for LS1021ATWR board Alison Wang
2014-08-19  2:55 ` [U-Boot] [PATCH v5 12/16] net: tsec: Remove tx snooping support from LS1 Alison Wang
2014-08-19  2:55 ` [U-Boot] [PATCH v5 13/16] serial: lpuart: add 32-bit registers lpuart support Alison Wang
2014-08-20 17:23   ` York Sun [this message]
2014-08-19  2:55 ` [U-Boot] [PATCH v5 14/16] video: dcu: Add DCU driver support Alison Wang
2014-08-19  2:55 ` [U-Boot] [PATCH v5 15/16] ls102xa: dcu: Add platform support for DCU on LS1021ATWR board Alison Wang
2014-08-20 17:26   ` York Sun
2014-08-19  2:55 ` [U-Boot] [PATCH v5 16/16] video: dcu: Add Sii9022A HDMI Transmitter support Alison Wang

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=53F4D996.5060505@freescale.com \
    --to=yorksun@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