/*
 * icd.h
 *
 * Copyright 2011 Sony Corporation.
 *
 * 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 __CONFIG_H
#define __CONFIG_H

#define CONFIG_SKIP_RELOCATE_UBOOT
#define CONFIG_SKIP_LOWLEVEL_INIT

#define CONFIG_EMEV_EMMC_1Piece		1	/* 0:eMMC 2pieces 1:eMMC 1piece */

#if defined(CONFIG_EMXX_EMMCBOOT) || defined(CONFIG_EMXX_SDBOOT)
	#define CONFIG_EMXX_MMCBOOT
#endif


/*
 * High Level Configuration Options
 */
#define CONFIG_EMXX					1	/* EMMA Mobile series */
#define CONFIG_MACH_EMGR			1

#define CONFIG_CMDLINE_TAG				/* enable passing of ATAGs */

#undef CONFIG_USE_IRQ					/* no support for IRQs */

#define CONFIG_DISPLAY_BOARDINFO
#define CONFIG_AUTO_COMPLETE

#define CONFIG_IDENT_STRING			" " ICX_VERSION_STRING " for ICD on EM1/EV0 rc4 at 20110922"


/*
 * Size of malloc() pool
 */
#define CONFIG_SYS_MALLOC_LEN		(CONFIG_ENV_SIZE + 128*1024)
#define CONFIG_SYS_GBL_DATA_SIZE	128	/* size in bytes reserved for initial data */


/*-----------------------------------------------------------------------
 * Hardware drivers
 */

#define EMXX_LANC_BASE				0x20000000

#ifdef CONFIG_EMGR_USE_DM9000
	/* ---- Configuration for the Ethernet Driver (DM9000) ---- */
	#define CONFIG_DRIVER_DM9000
	#define CONFIG_DM9000_BASE		EMXX_LANC_BASE
	#define DM9000_IO				(CONFIG_DM9000_BASE + 0x00000000)
	#define DM9000_DATA				(CONFIG_DM9000_BASE + 0x00020000)
	#define CONFIG_NET_RETRY_COUNT	(20+5)
	#define CONFIG_PING_TIMEOUT		100000UL /* 100msec */

	#ifdef DEBUG
		#define CONFIG_DM9000_DEBUG
	#endif
#else
	/* ---- Configuration for the Ethernet Driver (LAN9118) ---- */
	#define CONFIG_DRIVER_SMSC9118
	#define CONFIG_SMSC9118_BASE	EMXX_LANC_BASE
#endif /* CONFIG_EMGR_USE_DM9000 */

/* ---- Configuration for the Console Driver (NS16550) ---- */
#define CONFIG_SYS_NS16550
#define CONFIG_SYS_NS16550_SERIAL
#define CONFIG_SYS_NS16550_REG_SIZE	(4)
#define CONFIG_SYS_NS16550_CLK		(229376000/2)	/* PLL3(229.376MHz) divided by 2 */
#define CONFIG_SYS_NS16550_COM1		0xe1020000
#define CONFIG_CONS_INDEX			1

#define CONFIG_BAUDRATE				115200
#define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200, 230400, 460800 }

/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE


/*-----------------------------------------------------------------------
 * Command line configuration.
 */
#define CONFIG_SYS_NO_FLASH

#include <config_cmd_default.h>

#define CONFIG_CMDLINE_EDITING		1

#define	CONFIG_CMD_ICD

#define CONFIG_CMD_DHCP
#define CONFIG_CMD_PING

#undef CONFIG_CMD_FPGA		/* FPGA configuration Support	*/
#undef CONFIG_CMD_SETGETDCR	/* DCR support on 4xx		*/

/* RAM FS */
#define CONFIG_INITRD_TAG

#define CONFIG_FUINITRD_START_ADDR	0x42000000
#define CONFIG_FUINITRD_SIZE		(17 * 1024 * 1024)


/*-----------------------------------------------------------------------
 * Environment information
 */
#define CONFIG_ZERO_BOOTDELAY_CHECK	1
#define CONFIG_BOOTDELAY			0

//#define CONFIG_SILENT_CONSOLE		1
//#define	CONFIG_PWD				1
#define CONFIG_MD5					1

/* root file system */
#ifdef CONFIG_EMXX_EMMCBOOT
	#define CONFIG_EXT3_ROOT	"/dev/mmcblk0p3"	/* emmc-boot or esd-boot */
#elif CONFIG_EMEV_EMMC_1Piece
	#define CONFIG_EXT3_ROOT	"/dev/mmcblk1p3"	/* sd-boot (emmc 1 device) */
#else
	#define CONFIG_EXT3_ROOT	"/dev/mmcblk2p3"	/* sd-boot (emmc 2 device) */
#endif

/* Console */
#define	CONFIG_CONSOLE			""
#define	CONFIG_LOGLVL			"6"

/* DDR */
#define CONFIG_DDR				""

/* others */
#define CONFIG_OTHERS			""

/* default command line */
#define CONFIG_BOOTARGS					\
	"root=" CONFIG_EXT3_ROOT " "		\
	"noinitrd "							\
	"init=/init "						\
	"\$(console) "						\
	"loglevel=\$(loglevel) "			\
	"SELINUX_INIT=no "					\
	"rw "								\
	"video=qfb: "						\
	"ip=none "							\
	"rootfstype=ext3 "					\
	"rootwait "							\
	"\$(others) "						\

#define BOOTARGS_INST					\
	"root=/dev/ram "					\
	"init=/linuxrc_inst "				\
	"\$(console) "						\
	"SELINUX_INIT=no "					\
	"rw "								\
	"video=qfb: "						\
	"ip=none "

#define BOOTARGS_FWUP					\
	"root=/dev/ram "					\
	"init=/linuxrc_fwup "				\
	"\$(console) "						\
	"SELINUX_INIT=no "					\
	"rw "								\
	"video=qfb: "						\
	"ip=none "

#define BOOTARGS_EMRG					\
	"root=/dev/ram "					\
	"init=/linuxrc "					\
	"\$(console) "						\
	"SELINUX_INIT=no "					\
	"rw "								\
	"video=qfb: "						\
	"ip=none "

#define BOOTARGS_NFS																\
	"root=/dev/nfs "																\
	"noinitrd "																		\
	"init=/linuxrc "																\
	"\$(console) "																	\
	"SELINUX_INIT=no "																\
	"rw "																			\
	"video=qfb: "																	\
	"nfsroot=\$(serverip):\$(rootpath),tcp,timeo=30 "								\
	"ip=\$(ipaddr):\$(serverip):\$(gatewayip):\$(netmask):\$(hostname):eth0:off "

/* boot command */
#define CONFIG_ICD_EXT3CMD																\
	"setenv bootargs "																	\
		"root=\$(ext3_root) "															\
		"noinitrd "																		\
		"init=/init "																	\
		"\$(console) "																	\
		"loglevel=\$(loglevel) "														\
		"SELINUX_INIT=no "																\
		"rw "																			\
		"video=qfb: "																	\
		"ip=none "																		\
		"rootfstype=ext3 "																\
		"rootwait "																		\
		"\$(others)\;"																	\
	"icxboot"

#define CONFIG_ICD_NFSCMD																\
	"setenv bootargs "																	\
		"root=/dev/nfs "																\
		"noinitrd "																		\
		"init=/linuxrc "																\
		"\$(console) "																	\
		"loglevel=\$(loglevel) "														\
		"SELINUX_INIT=no "																\
		"rw "																			\
		"video=qfb: "																	\
		"nfsroot=\$(serverip):\$(rootpath),tcp,timeo=30 "								\
		"ip=\$(ipaddr):\$(serverip):\$(gatewayip):\$(netmask):\$(hostname):eth0:off "	\
		"\$(others)\;"																	\
	"icxboot"

#define CONFIG_EXT3CMD																	\
	"setenv bootargs "																	\
		"root=\$(ext3_root) "															\
		"noinitrd "																		\
		"init=/init "																	\
		"\$(console) "																	\
		"loglevel=\$(loglevel) "														\
		"SELINUX_INIT=no "																\
		"rw "																			\
		"video=qfb: "																	\
		"ip=none "																		\
		"rootfstype=ext3 "																\
		"rootwait "																		\
		"\$(others)\;"																	\
	"bootm 40007fc0"

#define CONFIG_NFSCMD																	\
	"setenv bootargs "																	\
		"root=/dev/nfs "																\
		"noinitrd "																		\
		"init=/linuxrc "																\
		"\$(console) "																	\
		"loglevel=\$(loglevel) "														\
		"SELINUX_INIT=no "																\
		"rw "																			\
		"video=qfb: "																	\
		"nfsroot=\$(serverip):\$(rootpath),tcp,timeo=30 "								\
		"ip=\$(ipaddr):\$(serverip):\$(gatewayip):\$(netmask):\$(hostname):eth0:off "	\
		"\$(others)\;"																	\
	"bootm 40007fc0"

#define CONFIG_BOOTCOMMAND	"icxboot"

//[TODO ICD] silent, pwd
#define CONFIG_EXTRA_ENV_SETTINGS				\
	"silent="		"0"					"\0"	\
	"pwd="			"0"					"\0"	\
	"console="		CONFIG_CONSOLE		"\0"	\
	"loglevel="		CONFIG_LOGLVL		"\0"	\
	"ext3_root="	CONFIG_EXT3_ROOT	"\0"	\
	"others="		CONFIG_OTHERS		"\0"	\
	"icx_ext3cmd="	CONFIG_ICD_EXT3CMD	"\0"	\
	"icx_nfscmd="	CONFIG_ICD_NFSCMD	"\0"	\
	"ext3cmd="		CONFIG_EXT3CMD		"\0"	\
	"nfscmd="		CONFIG_NFSCMD		"\0"

#define CONFIG_ETHADDR		80:7f:80:7f:80:7f
#define CONFIG_IPADDR		192.168.1.100
#define CONFIG_SERVERIP		192.168.1.1
#define CONFIG_GATEWAYIP	192.168.1.1
#define CONFIG_NETMASK		255.255.255.0
#define CONFIG_BOOTFILE		uImage
#define CONFIG_ROOTPATH		/export/rootfs


/*-----------------------------------------------------------------------
 * Miscellaneous configurable options
 */
#define CONFIG_SYS_LONGHELP								/* undef to save memory			*/
#define CONFIG_SYS_PROMPT			"EM/EV0 # "			/* the primary prompt string	*/
#define CONFIG_SYS_CBSIZE			512					/* Console I/O Buffer Size		*/

/* Print Buffer Size */
#define CONFIG_SYS_PBSIZE			(CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
#define CONFIG_SYS_MAXARGS			24					/* max number of command args	*/
#define CONFIG_SYS_BARGSIZE			CONFIG_SYS_CBSIZE	/* Boot Argument Buffer Size	*/

#define CONFIG_SYS_MEMTEST_START	0x41100000			/* memtest works on				*/
#define CONFIG_SYS_MEMTEST_END		0x4fffffff			/* (256-17)MB in DRAM			*/

/* MEM TEST */
#define CONFIG_SYS_ALT_MEMTEST		1

#undef  CONFIG_SYS_CLKS_IN_HZ		/* everything, incl board info, in Hz */
#define CONFIG_SYS_LOAD_ADDR		0x40007fc0			/* default load address			*/
#define	CONFIG_SYS_LOAD_SIZE		0x480000			/* 4.5MByte						*/

#define CONFIG_KERNEL_LOAD_ADDR		0x40008000			/* kernel image load addr		*/


/*-----------------------------------------------------------------------
 * Timer
 */
#define CFG_HZ						32768
#define CONFIG_SYS_HZ				CFG_HZ
#define CONFIG_SYS_TIMERBASE		0xe0000000	/* use TI0 */


/*-----------------------------------------------------------------------
 * Stack sizes
 *
 * The stack sizes are set up in start.S using the settings below
 */
#define CONFIG_STACKSIZE			(128*1024)	/* regular stack */

#ifdef CONFIG_USE_IRQ
	#define CONFIG_STACKSIZE_IRQ	(4*1024)	/* IRQ stack */
	#define CONFIG_STACKSIZE_FIQ	(4*1024)	/* FIQ stack */
#endif


/*-----------------------------------------------------------------------
 * Physical Memory Map
 */
#define CONFIG_NR_DRAM_BANKS		2			/* we have 2 bank of DRAM */
#define PHYS_SDRAM_SIZE				0x04000000	/*  64 MB	*/

#define PHYS_SDRAM_1				0x40000000							/* SDRAM Bank #1 */
#define PHYS_SDRAM_1_SIZE			PHYS_SDRAM_SIZE
#define PHYS_SDRAM_2				(PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)	/* SDRAM Bank #2 */
#define PHYS_SDRAM_2_SIZE			PHYS_SDRAM_SIZE

#define CONFIG_SETUP_MEMORY_TAGS	1	/* send memory definition to kernel */ 

#define	CONFIG_ATAG_MEM_1_ADDR		PHYS_SDRAM_1		/* Bank1 */
#define CONFIG_ATAG_MEM_1_SIZE		0x01F00000

#define	CONFIG_ATAG_MEM_2_ADDR		0x42000000			/* Bank2 */
#define CONFIG_ATAG_MEM_2_SIZE_512	0x01200000
#define CONFIG_ATAG_MEM_2_SIZE_1G	0x02000000

#define	CONFIG_ATAG_MEM_2_ADDR_FU	CONFIG_FUINITRD_START_ADDR
#define CONFIG_ATAG_MEM_2_SIZE_FU	0x02000000

#define	CONFIG_ATAG_MEM_3_ADDR		0x44000000			/* Bank3 */
#define CONFIG_ATAG_MEM_3_SIZE_1G	0x01B00000

#define	CONFIG_RESET_FLAG_ADDR		0x41FFFFFC			/* end of 1st bank in SDRAM */


/*-----------------------------------------------------------------------
 * Environment organization
 */
#define CONFIG_ENV_SIZE				0x00004000			/* 16 KB sectors								*/

#define CONFIG_ENV_IS_IN_MMC

/* mmc common configuration */
#define CONFIG_MMC_PARTS			4					/* number of memory partitions					*/
#define CONFIG_MMC_BLOCKS			0x1000000			/* 8GB											*/
#define CONFIG_MMC_SECT_OF_BLOCKS	0x2000				/* 1[sector] == 8192[block] * 512[byte]			*/
#define CONFIG_MMC_SECTS			(CONFIG_MMC_BLOCKS / CONFIG_MMC_SECT_OF_BLOCKS)	/* 0x800[sector]	*/

#define CONFIG_MMC_PROTECT_TBL		0xf0001000			/* protect table address						*/
#define CONFIG_MMC_PROTECT_TBL_SIZE	CONFIG_MMC_SECTS	/* protect table size (0x800[byte])				*/
#define CONFIG_ENV_TMP_ADDR			0x410C0000			/* 0x410C0000 - 0x410FFFFF						*/

/* addr of environment */
#ifdef CONFIG_EMXX_SDBOOT
	#define CONFIG_ENV_OFFSET		0x0					/* environment starts p2 + here					*/
#else	/* defined(CONFIG_EMXX_EMMCBOOT) */
	#define CONFIG_ENV_OFFSET		0x1e0				/* environment starts p1 + here					*/
#endif

/*-----------------------------------------------------------------------*/

#endif	/* __CONFIG_H */
