[U-Boot] [PATCH 4/8] ZOOM2 Add serial support.

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Thu Apr 2 22:21:22 CEST 2009


On 22:02 Wed 01 Apr     , Tom Rix wrote:
> Zoom2 serial is in general supplied by one of the 4 UARTS on the debug board.
> The default serial is from the USB connector on left side of the debug board.
> The USB connector will produce 2 of the 4 UARTS.  On your host pick the first
> enumeration.
> 
> The serial port set up is the same with Zoom1.
> Baud rate 115200, 8 bit data, no parity, 1 stop bit, no flow.
> 
> The kernel bootargs are
> console=ttyS3,115200n8
> 
> Signed-off-by: Tom Rix <Tom.Rix at windriver.com>
> ---
>  board/omap3/zoom2/Makefile       |    3 +-
>  board/omap3/zoom2/zoom2_serial.c |  134 ++++++++++++++++++++++++++++++++++++++
>  board/omap3/zoom2/zoom2_serial.h |   77 ++++++++++++++++++++++
>  common/serial.c                  |    2 +
>  cpu/arm_cortexa8/omap3/mem.c     |   23 +++++++
>  drivers/serial/ns16550.c         |    4 +-
>  include/asm-arm/arch-omap3/cpu.h |    2 +
>  include/configs/omap3_zoom2.h    |   28 ++++----
>  include/ns16550.h                |   19 ++++++
>  include/serial.h                 |    7 ++
>  10 files changed, 282 insertions(+), 17 deletions(-)
>  create mode 100644 board/omap3/zoom2/zoom2_serial.c
>  create mode 100644 board/omap3/zoom2/zoom2_serial.h
> 
> diff --git a/board/omap3/zoom2/Makefile b/board/omap3/zoom2/Makefile
> index b8fa5a7..d27990c 100644
> --- a/board/omap3/zoom2/Makefile
> +++ b/board/omap3/zoom2/Makefile
> @@ -26,7 +26,8 @@ include $(TOPDIR)/config.mk
>  LIB	= $(obj)lib$(BOARD).a
>  
>  COBJS	:= zoom2.o \
> -	debug_board.o
> +	debug_board.o \
> +	zoom2_serial.o
it could be nice to disactivate it
>  
>  SRCS	:= $(COBJS:.o=.c)
>  OBJS	:= $(addprefix $(obj),$(COBJS))
> diff --git a/board/omap3/zoom2/zoom2_serial.c b/board/omap3/zoom2/zoom2_serial.c
> new file mode 100644
> index 0000000..e879962
> --- /dev/null
> +++ b/board/omap3/zoom2/zoom2_serial.c
> @@ -0,0 +1,134 @@
> +/*
> + * (C) Copyright 2009
> + * Wind River, <www.windriver.com>
> + * Tom Rix <Tom.Rix at windriver.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + *
> + * This file was adapted from cpu/mpc5xxx/serial.c
> + *
> + */
> +
> +#include "zoom2_serial.h"
> +
> +int zoom2_debug_board_connected (void);
please move to a header
> +
> +int quad_init_dev (unsigned long base)
> +{
> +	/*
> +	 * The Quad UART is on the debug board.
> +	 * Check if the debug board is attached before using the UART
> +	 */
> +	if (zoom2_debug_board_connected ()) {
> +		NS16550_t com_port = (NS16550_t) base;
> +		int baud_divisor = CONFIG_SYS_NS16550_CLK / 16 /
> +		    CONFIG_BAUDRATE;
aligning it with CONFIG_SYS_NS16550_CLK could be nice
please add an empty line
> +		/*
> +		 * Zoom2 has a board specific initialization of its UART.
> +		 * This generic initialization has been copied from
> +		 * drivers/serial/ns16550.c. The macros have been expanded.
> +		 *
> +		 * Do the following instead of
> +		 *
> +		 * NS16550_init (port, clock_divisor);
> +		 */
> +		com_port->ier = 0x00;
> +
> +		/*
> +		 * On Zoom2 board Set pre-scalar to 1
> +		 * CLKSEL is GND => MCR[7] is 1 => preslr is 4
> +		 * So change the prescl to 1
> +		 */
> +		com_port->lcr = 0xBF;
> +		com_port->fcr |= 0x10;
> +		com_port->mcr &= 0x7F;
> +
> +		com_port->lcr = LCR_BKSE | LCR_8N1;
> +		com_port->dll = 0;
> +		com_port->dlm = 0;
> +		com_port->lcr = LCR_8N1;
> +		com_port->mcr = (MCR_DTR | MCR_RTS);
> +		com_port->fcr = (FCR_FIFO_EN | FCR_RXSR | FCR_TXSR);
> +		com_port->lcr = LCR_BKSE | LCR_8N1;
> +		com_port->dll = baud_divisor & 0xff;
> +		com_port->dlm = (baud_divisor >> 8) & 0xff;
> +		com_port->lcr = LCR_8N1;
clould you explain a fe more what you do here?
> +	}
> +	/*
> +	 * We have to lie here, otherwise the board init code will hang
> +	 * on the check
> +	 */
> +	return 0;
> +}
> +
> +void quad_putc_dev (unsigned long base, const char c)
> +{
> +	if (zoom2_debug_board_connected ()) {
> +		NS16550_t port = (NS16550_t) base;
> +
> +		if (c == '\n')
> +			quad_putc_dev (base, '\r');
> +
> +		NS16550_putc (port, c);
why not
		NS16550_putc ((NS16550_t) base, c);

> +	}
> +}
> +
> +void quad_puts_dev (unsigned long base, const char *s)
> +{
> +	if (zoom2_debug_board_connected ()) {
> +		while (*s)
> +			quad_putc_dev (base, *s++);
> +	}
> +}
> +
> +int quad_getc_dev (unsigned long base)
> +{
> +	if (zoom2_debug_board_connected ()) {
> +		NS16550_t port = (NS16550_t) base;
> +
> +		return NS16550_getc (port);
> +	} else {
> +		return 0;
> +	}
> +}
> +
> +int quad_tstc_dev (unsigned long base)
> +{
> +	if (zoom2_debug_board_connected ()) {
> +		NS16550_t port = (NS16550_t) base;
> +
> +		return NS16550_tstc (port);
> +	} else {
> +		return 0;
> +	}
> +}
> +
> +void quad_setbrg_dev (unsigned long base)
> +{
> +	if (zoom2_debug_board_connected ()) {
> +		NS16550_t port = (NS16550_t) base;
> +
> +		int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 /
> +		    CONFIG_BAUDRATE;
> +
> +		NS16550_reinit (port, clock_divisor);
why don't you use the same in in the imit?
> +	}
> +}
> +
> +QUAD_INIT (0)
> +QUAD_INIT (1)
> +QUAD_INIT (2)
> +QUAD_INIT (3)
> diff --git a/board/omap3/zoom2/zoom2_serial.h b/board/omap3/zoom2/zoom2_serial.h
> new file mode 100644
> index 0000000..49d64d0
> --- /dev/null
> +++ b/board/omap3/zoom2/zoom2_serial.h
> @@ -0,0 +1,77 @@
> +/*
> + * (C) Copyright 2009
> + * Wind River, <www.windriver.com>
> + * Tom Rix <Tom.Rix at windriver.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + *
> + */
> +
> +#ifndef ZOOM2_SERIAL_H
> +#define ZOOM2_SERIAL_H
> +
> +#include <common.h>
> +#include <serial.h>
> +#include <ns16550.h>
> +#include <asm/arch/cpu.h>
> +
> +#define QUAD_BASE_0      SERIAL_TL16CP754C_BASE
> +#define QUAD_BASE_1      (SERIAL_TL16CP754C_BASE + 0x100)
> +#define QUAD_BASE_2      (SERIAL_TL16CP754C_BASE + 0x200)
> +#define QUAD_BASE_3      (SERIAL_TL16CP754C_BASE + 0x300)
why not
#define QUAD_BASE(x)	(SERIAL_TL16CP754C_BASE + (x << 8))
> +
> +#define S(a) #a
> +#define N(a) S(quad##a)
> +#define U(a) S(UART##a)
> +
> +#define QUAD_INIT(n)                           \
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
white space please fix
> +int quad_init_##n(void)                        \
ditto and so on please fix
> +{                                              \
> +	return quad_init_dev(QUAD_BASE_##n);   \
> +}                                              \
> +void quad_setbrg_##n(void)                     \
> +{                                              \
> +	quad_setbrg_dev(QUAD_BASE_##n);        \
> +}                                              \
> +void quad_putc_##n(const char c)               \
> +{                                              \
> +	quad_putc_dev(QUAD_BASE_##n, c);       \
> +}                                              \
> +void quad_puts_##n(const char *s)              \
> +{                                              \
> +	quad_puts_dev(QUAD_BASE_##n, s);       \
> +}                                              \
> +int quad_getc_##n(void)                        \
> +{                                              \
> +	return quad_getc_dev(QUAD_BASE_##n);   \
> +}                                              \
> +int quad_tstc_##n(void)                        \
> +{                                              \
> +	return quad_tstc_dev(QUAD_BASE_##n);   \
> +}                                              \
> +struct serial_device zoom2_serial_device##n =  \
> +{                                              \
> +	N(n),				       \
> +	U(n),				       \
> +	quad_init_##n,                         \
> +	quad_setbrg_##n,                       \
> +	quad_getc_##n,                         \
> +	quad_tstc_##n,                         \
> +	quad_putc_##n,                         \
> +	quad_puts_##n,                         \
> +};
> +
> +#endif /* ZOOM2_SERIAL_H */
> diff --git a/common/serial.c b/common/serial.c
> index 09385d0..3e9135b 100644
> --- a/common/serial.c
> +++ b/common/serial.c
> @@ -68,6 +68,8 @@ struct serial_device *__default_serial_console (void)
>  #else
>  #error "CONFIG_SERIAL? missing."
>  #endif
> +#elif defined(CONFIG_OMAP3_ZOOM2)
> +		return DEFAULT_ZOOM2_SERIAL_DEVICE;
>  #else
>  #error No default console
>  #endif
> diff --git a/cpu/arm_cortexa8/omap3/mem.c b/cpu/arm_cortexa8/omap3/mem.c
> index 3cc22c4..20a8748 100644
> --- a/cpu/arm_cortexa8/omap3/mem.c
> +++ b/cpu/arm_cortexa8/omap3/mem.c
> @@ -82,6 +82,18 @@ gpmc_csx_t *onenand_cs_base;
>  
>  #endif
>  
> +#if defined(CONFIG_OMAP3_ZOOM2)
> +static u32 gpmc_serial_TL16CP754C[GPMC_MAX_REG] = {
> +	0x00011000,
> +	0x001F1F01,
> +	0x00080803,
> +	0x1D091D09,
> +	0x041D1F1F,
> +	0x1D0904C4, 0
> +};
> +gpmc_csx_t *serial_cs_base;
> +#endif
> +
>  static sdrc_t *sdrc_base = (sdrc_t *)OMAP34XX_SDRC_BASE;
>  
>  /**************************************************************************
> @@ -281,4 +293,15 @@ void gpmc_init(void)
>  	boot_flash_env_addr = f_off;
>  #endif
>  #endif
> +
> +#ifdef CONFIG_OMAP3_ZOOM2
> +	/* Configure console support on zoom2 */
> +	gpmc_config = gpmc_serial_TL16CP754C;
> +	serial_cs_base = (gpmc_csx_t *) (GPMC_CONFIG_CS0_BASE +
> +					 (3 * GPMC_CONFIG_WIDTH));
> +	enable_gpmc_config(gpmc_config,
> +			   serial_cs_base,
> +			   SERIAL_TL16CP754C_BASE,
> +			   GPMC_SIZE_16M);
> +#endif
it's board specific please move to board
>  }
> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
> index 397f5df..6ec6697 100644
> --- a/drivers/serial/ns16550.c
> +++ b/drivers/serial/ns16550.c
> @@ -14,7 +14,7 @@
>  void NS16550_init (NS16550_t com_port, int baud_divisor)
>  {
>  	com_port->ier = 0x00;
> -#ifdef CONFIG_OMAP
> +#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
a config could be better
>  	com_port->mdr1 = 0x7;	/* mode select reset TL16C750*/
>  #endif
>  	com_port->lcr = LCR_BKSE | LCRVAL;
> @@ -27,7 +27,7 @@ void NS16550_init (NS16550_t com_port, int baud_divisor)
>  	com_port->dll = baud_divisor & 0xff;
>  	com_port->dlm = (baud_divisor >> 8) & 0xff;
>  	com_port->lcr = LCRVAL;
> -#if defined(CONFIG_OMAP)
> +#if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
>  #if defined(CONFIG_APTIX)
>  	com_port->mdr1 = 3;	/* /13 mode so Aptix 6MHz can hit 115200 */
ditto
it it's possible to use the generic NS16550_init for the ZOOM2 it could be
better
>  #else
> diff --git a/include/asm-arm/arch-omap3/cpu.h b/include/asm-arm/arch-omap3/cpu.h
> index c544e0c..7671a3a 100644
> --- a/include/asm-arm/arch-omap3/cpu.h
> +++ b/include/asm-arm/arch-omap3/cpu.h
> @@ -153,6 +153,8 @@ typedef struct gpmc_csx {
>  #define PISMO2_BASE		0x18000000	/* PISMO2 CS1/2 */
>  #define ONENAND_MAP		0x20000000	/* OneNand addr */
>  						/* (actual size small port) */
> +#define SERIAL_TL16CP754C_BASE	0x10000000      /* Zoom2 Serial chip address */
it's not cpu specfic please move this to the serial driver
> +
>  /* SMS */
>  #ifndef __ASSEMBLY__
>  typedef struct sms {
> diff --git a/include/configs/omap3_zoom2.h b/include/configs/omap3_zoom2.h
> index 52e5f70..56b73eb 100644
> --- a/include/configs/omap3_zoom2.h
> +++ b/include/configs/omap3_zoom2.h
> @@ -70,26 +70,26 @@
>  
>  /*
>   * NS16550 Configuration
> + * Zoom2 uses the TL16CP754C on the debug board
>   */
> -#define V_NS16550_CLK			48000000	/* 48MHz (APLL96/2) */
> -
> -#define CONFIG_SYS_NS16550
> -#define CONFIG_SYS_NS16550_SERIAL
> -#define CONFIG_SYS_NS16550_REG_SIZE	(-4)
> -#define CONFIG_SYS_NS16550_CLK		V_NS16550_CLK
> -
> +#define CONFIG_SERIAL_MULTI      1
>  /*
> - * select serial console configuration
> + * 0 - 1 : first  USB with respect to the left edge of the debug board
> + * 2 - 3 : second USB with respect to the left edge of the debug board
>   */
> -#define CONFIG_CONS_INDEX		3
> -#define CONFIG_SYS_NS16550_COM3		OMAP34XX_UART3
> -#define CONFIG_SERIAL3			3	/* UART3 */
is the removed serial will work on the zoom2?

Best Regards,
J.


More information about the U-Boot mailing list