2007-05-13 11:58:00 +00:00
|
|
|
/*
|
2010-10-26 11:23:53 +00:00
|
|
|
* Copyright (C) 2007, 2008, 2010
|
2007-05-13 11:58:00 +00:00
|
|
|
* Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2007-05-13 11:58:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <malloc.h>
|
2009-05-16 10:14:54 +00:00
|
|
|
#include <stdio_dev.h>
|
2007-05-13 11:58:00 +00:00
|
|
|
#include <version.h>
|
2008-09-18 10:04:26 +00:00
|
|
|
#include <watchdog.h>
|
2007-05-13 11:58:00 +00:00
|
|
|
#include <net.h>
|
2012-03-21 05:48:34 +00:00
|
|
|
#include <mmc.h>
|
2007-05-13 11:58:00 +00:00
|
|
|
#include <environment.h>
|
|
|
|
|
2009-10-10 10:42:21 +00:00
|
|
|
#ifdef CONFIG_BITBANGMII
|
|
|
|
#include <miiphy.h>
|
|
|
|
#endif
|
|
|
|
|
2010-12-21 01:27:51 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2007-05-13 11:58:00 +00:00
|
|
|
extern int cpu_init(void);
|
|
|
|
extern int board_init(void);
|
|
|
|
extern int dram_init(void);
|
|
|
|
extern int timer_init(void);
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2011-03-07 02:21:40 +00:00
|
|
|
#ifndef CONFIG_SYS_NO_FLASH
|
2007-09-22 17:12:30 +00:00
|
|
|
static int sh_flash_init(void)
|
|
|
|
{
|
|
|
|
gd->bd->bi_flashsize = flash_init();
|
2010-10-26 11:23:53 +00:00
|
|
|
|
|
|
|
if (gd->bd->bi_flashsize >= (1024 * 1024))
|
2010-12-29 00:12:05 +00:00
|
|
|
printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
|
2010-10-26 11:23:53 +00:00
|
|
|
else
|
2010-12-29 00:12:05 +00:00
|
|
|
printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
|
2007-09-22 17:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-07 02:21:40 +00:00
|
|
|
#endif /* CONFIG_SYS_NO_FLASH */
|
2007-09-22 17:12:30 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_CMD_NAND)
|
2008-09-18 10:04:26 +00:00
|
|
|
# include <nand.h>
|
|
|
|
# define INIT_FUNC_NAND_INIT nand_init,
|
|
|
|
#else
|
|
|
|
# define INIT_FUNC_NAND_INIT
|
2007-09-22 17:12:30 +00:00
|
|
|
#endif /* CONFIG_CMD_NAND */
|
|
|
|
|
2008-09-18 10:04:26 +00:00
|
|
|
#if defined(CONFIG_WATCHDOG)
|
|
|
|
extern int watchdog_init(void);
|
|
|
|
extern int watchdog_disable(void);
|
2013-03-05 14:39:42 +00:00
|
|
|
# undef INIT_FUNC_WATCHDOG_INIT
|
2008-09-18 10:04:26 +00:00
|
|
|
# define INIT_FUNC_WATCHDOG_INIT watchdog_init,
|
|
|
|
# define WATCHDOG_DISABLE watchdog_disable
|
|
|
|
#else
|
|
|
|
# define INIT_FUNC_WATCHDOG_INIT
|
|
|
|
# define WATCHDOG_DISABLE
|
|
|
|
#endif /* CONFIG_WATCHDOG */
|
|
|
|
|
2007-09-22 17:12:30 +00:00
|
|
|
#if defined(CONFIG_CMD_IDE)
|
2008-09-18 10:04:26 +00:00
|
|
|
# include <ide.h>
|
|
|
|
# define INIT_FUNC_IDE_INIT ide_init,
|
|
|
|
#else
|
|
|
|
# define INIT_FUNC_IDE_INIT
|
|
|
|
#endif /* CONFIG_CMD_IDE */
|
2007-09-22 17:12:30 +00:00
|
|
|
|
2008-03-05 05:30:02 +00:00
|
|
|
#if defined(CONFIG_PCI)
|
2008-09-18 10:04:26 +00:00
|
|
|
#include <pci.h>
|
2008-03-05 05:30:02 +00:00
|
|
|
static int sh_pci_init(void)
|
|
|
|
{
|
|
|
|
pci_init();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-18 10:04:26 +00:00
|
|
|
# define INIT_FUNC_PCI_INIT sh_pci_init,
|
|
|
|
#else
|
|
|
|
# define INIT_FUNC_PCI_INIT
|
2008-03-05 05:30:02 +00:00
|
|
|
#endif /* CONFIG_PCI */
|
|
|
|
|
2007-09-22 17:12:30 +00:00
|
|
|
static int sh_mem_env_init(void)
|
|
|
|
{
|
2010-10-26 12:34:52 +00:00
|
|
|
mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
|
2009-08-22 04:05:20 +00:00
|
|
|
CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
|
2007-09-22 17:12:30 +00:00
|
|
|
env_relocate();
|
|
|
|
jumptable_init();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-05 08:18:38 +00:00
|
|
|
#if defined(CONFIG_CMD_MMC)
|
|
|
|
static int sh_mmc_init(void)
|
|
|
|
{
|
|
|
|
puts("MMC: ");
|
|
|
|
mmc_initialize(gd->bd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-13 11:58:00 +00:00
|
|
|
typedef int (init_fnc_t) (void);
|
|
|
|
|
|
|
|
init_fnc_t *init_sequence[] =
|
|
|
|
{
|
|
|
|
cpu_init, /* basic cpu dependent setup */
|
|
|
|
board_init, /* basic board dependent setup */
|
2008-09-18 10:04:26 +00:00
|
|
|
interrupt_init, /* set up exceptions */
|
2007-05-13 11:58:00 +00:00
|
|
|
env_init, /* event init */
|
2008-09-18 10:04:26 +00:00
|
|
|
serial_init, /* SCIF init */
|
|
|
|
INIT_FUNC_WATCHDOG_INIT /* watchdog init */
|
2007-05-13 11:58:00 +00:00
|
|
|
console_init_f,
|
|
|
|
display_options,
|
|
|
|
checkcpu,
|
2007-09-22 17:12:30 +00:00
|
|
|
checkboard, /* Check support board */
|
2007-05-13 11:58:00 +00:00
|
|
|
dram_init, /* SDRAM init */
|
2007-09-22 17:12:30 +00:00
|
|
|
timer_init, /* SuperH Timer (TCNT0 only) init */
|
|
|
|
sh_mem_env_init,
|
2011-03-07 02:21:40 +00:00
|
|
|
#ifndef CONFIG_SYS_NO_FLASH
|
|
|
|
sh_flash_init, /* Flash memory init*/
|
|
|
|
#endif
|
2008-09-18 10:04:26 +00:00
|
|
|
INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
|
|
|
|
INIT_FUNC_PCI_INIT /* PCI init */
|
2009-05-16 10:14:54 +00:00
|
|
|
stdio_init,
|
2007-09-22 17:12:30 +00:00
|
|
|
console_init_r,
|
|
|
|
interrupt_init,
|
2011-10-20 04:19:47 +00:00
|
|
|
#ifdef CONFIG_BOARD_LATE_INIT
|
2007-09-22 17:12:30 +00:00
|
|
|
board_late_init,
|
|
|
|
#endif
|
2011-07-05 08:18:38 +00:00
|
|
|
#if defined(CONFIG_CMD_MMC)
|
|
|
|
sh_mmc_init,
|
2007-09-22 17:12:30 +00:00
|
|
|
#endif
|
2007-05-13 11:58:00 +00:00
|
|
|
NULL /* Terminate this list */
|
|
|
|
};
|
|
|
|
|
2008-09-18 10:04:26 +00:00
|
|
|
void sh_generic_init(void)
|
2007-05-13 11:58:00 +00:00
|
|
|
{
|
|
|
|
bd_t *bd;
|
|
|
|
init_fnc_t **init_fnc_ptr;
|
|
|
|
|
2010-10-26 12:34:52 +00:00
|
|
|
memset(gd, 0, GENERATED_GBL_DATA_SIZE);
|
2007-05-13 11:58:00 +00:00
|
|
|
|
|
|
|
gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
|
|
|
|
|
2008-09-18 10:04:26 +00:00
|
|
|
gd->bd = (bd_t *)(gd + 1); /* At end of global data */
|
2007-05-13 11:58:00 +00:00
|
|
|
gd->baudrate = CONFIG_BAUDRATE;
|
|
|
|
|
|
|
|
gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
|
|
|
|
|
|
|
|
bd = gd->bd;
|
2008-10-16 13:01:15 +00:00
|
|
|
bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
|
|
|
|
bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
|
2011-03-07 02:21:40 +00:00
|
|
|
#ifndef CONFIG_SYS_NO_FLASH
|
2008-10-16 13:01:15 +00:00
|
|
|
bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
|
2011-03-07 02:21:40 +00:00
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
|
|
|
|
bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
|
|
|
|
bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
|
2007-05-13 11:58:00 +00:00
|
|
|
#endif
|
|
|
|
bd->bi_baudrate = CONFIG_BAUDRATE;
|
|
|
|
|
2008-09-18 10:04:26 +00:00
|
|
|
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
|
|
|
|
WATCHDOG_RESET();
|
|
|
|
if ((*init_fnc_ptr) () != 0)
|
2007-05-13 11:58:00 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2008-09-18 10:04:26 +00:00
|
|
|
#ifdef CONFIG_WATCHDOG
|
|
|
|
/* disable watchdog if environment is set */
|
|
|
|
{
|
|
|
|
char *s = getenv("watchdog");
|
|
|
|
if (s != NULL)
|
|
|
|
if (strncmp(s, "off", 3) == 0)
|
|
|
|
WATCHDOG_DISABLE();
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WATCHDOG*/
|
2007-09-22 17:12:30 +00:00
|
|
|
|
2008-09-18 10:04:26 +00:00
|
|
|
|
2009-10-10 10:42:21 +00:00
|
|
|
#ifdef CONFIG_BITBANGMII
|
|
|
|
bb_miiphy_init();
|
|
|
|
#endif
|
2008-09-18 10:04:26 +00:00
|
|
|
#if defined(CONFIG_CMD_NET)
|
2012-04-04 18:53:41 +00:00
|
|
|
puts("Net: ");
|
|
|
|
eth_initialize(gd->bd);
|
2007-09-22 17:12:30 +00:00
|
|
|
#endif /* CONFIG_CMD_NET */
|
|
|
|
|
2007-05-13 11:58:00 +00:00
|
|
|
while (1) {
|
2008-09-18 10:04:26 +00:00
|
|
|
WATCHDOG_RESET();
|
2007-05-13 11:58:00 +00:00
|
|
|
main_loop();
|
|
|
|
}
|
|
|
|
}
|