blob: 69cdca3744f9cd72f2bdfa449e7b0ed63a65d264 [file] [log] [blame]
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09001/*
Nobuhiro Iwamatsu0db11c22010-10-26 20:23:53 +09002 * Copyright (C) 2007, 2008, 2010
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09003 * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09006 */
7
8#include <common.h>
9#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070010#include <console.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090011#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020012#include <stdio_dev.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090013#include <version.h>
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090014#include <watchdog.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090015#include <net.h>
Nobuhiro Iwamatsu2ba44e12012-03-21 14:48:34 +090016#include <mmc.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090017#include <environment.h>
18
Luigi 'Comio' Mantellini01db1552009-10-10 12:42:21 +020019#ifdef CONFIG_BITBANGMII
20#include <miiphy.h>
21#endif
22
John Rigby0d21ed02010-12-20 18:27:51 -070023DECLARE_GLOBAL_DATA_PTR;
24
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090025extern int cpu_init(void);
26extern int board_init(void);
27extern int dram_init(void);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090028extern int timer_init(void);
29
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020030unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090031
Nobuhiro Iwamatsue6571672011-03-07 11:21:40 +090032#ifndef CONFIG_SYS_NO_FLASH
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090033static int sh_flash_init(void)
34{
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090035 gd->bd->bi_flashsize = flash_init();
Nobuhiro Iwamatsu0db11c22010-10-26 20:23:53 +090036
37 if (gd->bd->bi_flashsize >= (1024 * 1024))
Peter Tyser0b5a2632010-12-28 18:12:05 -060038 printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
Nobuhiro Iwamatsu0db11c22010-10-26 20:23:53 +090039 else
Peter Tyser0b5a2632010-12-28 18:12:05 -060040 printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090041
42 return 0;
43}
Nobuhiro Iwamatsue6571672011-03-07 11:21:40 +090044#endif /* CONFIG_SYS_NO_FLASH */
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090045
46#if defined(CONFIG_CMD_NAND)
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090047# include <nand.h>
48# define INIT_FUNC_NAND_INIT nand_init,
49#else
50# define INIT_FUNC_NAND_INIT
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090051#endif /* CONFIG_CMD_NAND */
52
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090053#if defined(CONFIG_WATCHDOG)
54extern int watchdog_init(void);
55extern int watchdog_disable(void);
Simon Glass6f984902013-03-05 14:39:42 +000056# undef INIT_FUNC_WATCHDOG_INIT
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090057# define INIT_FUNC_WATCHDOG_INIT watchdog_init,
58# define WATCHDOG_DISABLE watchdog_disable
59#else
60# define INIT_FUNC_WATCHDOG_INIT
61# define WATCHDOG_DISABLE
62#endif /* CONFIG_WATCHDOG */
63
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090064#if defined(CONFIG_CMD_IDE)
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090065# include <ide.h>
66# define INIT_FUNC_IDE_INIT ide_init,
67#else
68# define INIT_FUNC_IDE_INIT
69#endif /* CONFIG_CMD_IDE */
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090070
Yusuke Godac77aa172008-03-05 14:30:02 +090071#if defined(CONFIG_PCI)
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090072#include <pci.h>
Yusuke Godac77aa172008-03-05 14:30:02 +090073static int sh_pci_init(void)
74{
75 pci_init();
76 return 0;
77}
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090078# define INIT_FUNC_PCI_INIT sh_pci_init,
79#else
80# define INIT_FUNC_PCI_INIT
Yusuke Godac77aa172008-03-05 14:30:02 +090081#endif /* CONFIG_PCI */
82
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090083static int sh_mem_env_init(void)
84{
Wolfgang Denk0191e472010-10-26 14:34:52 +020085 mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
Peter Tysered527702009-08-21 23:05:20 -050086 CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090087 env_relocate();
88 jumptable_init();
89 return 0;
90}
91
Yoshihiro Shimoda062fbbf2011-07-05 17:18:38 +090092#if defined(CONFIG_CMD_MMC)
93static int sh_mmc_init(void)
94{
95 puts("MMC: ");
96 mmc_initialize(gd->bd);
97 return 0;
98}
99#endif
100
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900101typedef int (init_fnc_t) (void);
102
103init_fnc_t *init_sequence[] =
104{
105 cpu_init, /* basic cpu dependent setup */
106 board_init, /* basic board dependent setup */
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900107 interrupt_init, /* set up exceptions */
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900108 env_init, /* event init */
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900109 serial_init, /* SCIF init */
110 INIT_FUNC_WATCHDOG_INIT /* watchdog init */
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900111 console_init_f,
112 display_options,
113 checkcpu,
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +0900114 checkboard, /* Check support board */
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900115 dram_init, /* SDRAM init */
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +0900116 timer_init, /* SuperH Timer (TCNT0 only) init */
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +0900117 sh_mem_env_init,
Nobuhiro Iwamatsue6571672011-03-07 11:21:40 +0900118#ifndef CONFIG_SYS_NO_FLASH
119 sh_flash_init, /* Flash memory init*/
120#endif
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900121 INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
122 INIT_FUNC_PCI_INIT /* PCI init */
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200123 stdio_init,
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +0900124 console_init_r,
125 interrupt_init,
Helmut Raigerd5a184b2011-10-20 04:19:47 +0000126#ifdef CONFIG_BOARD_LATE_INIT
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +0900127 board_late_init,
128#endif
Yoshihiro Shimoda062fbbf2011-07-05 17:18:38 +0900129#if defined(CONFIG_CMD_MMC)
130 sh_mmc_init,
131#endif
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900132 NULL /* Terminate this list */
133};
134
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900135void sh_generic_init(void)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900136{
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900137 bd_t *bd;
138 init_fnc_t **init_fnc_ptr;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900139
Wolfgang Denk0191e472010-10-26 14:34:52 +0200140 memset(gd, 0, GENERATED_GBL_DATA_SIZE);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900141
142 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
143
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900144 gd->bd = (bd_t *)(gd + 1); /* At end of global data */
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900145 gd->baudrate = CONFIG_BAUDRATE;
146
147 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
148
149 bd = gd->bd;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200150 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
151 bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
Nobuhiro Iwamatsue6571672011-03-07 11:21:40 +0900152#ifndef CONFIG_SYS_NO_FLASH
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
Nobuhiro Iwamatsue6571672011-03-07 11:21:40 +0900154#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200155#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
156 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
157 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900158#endif
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900159
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900160 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
161 WATCHDOG_RESET();
162 if ((*init_fnc_ptr) () != 0)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900163 hang();
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900164 }
165
166#ifdef CONFIG_WATCHDOG
167 /* disable watchdog if environment is set */
168 {
169 char *s = getenv("watchdog");
170 if (s != NULL)
171 if (strncmp(s, "off", 3) == 0)
172 WATCHDOG_DISABLE();
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900173 }
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900174#endif /* CONFIG_WATCHDOG*/
175
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900176
Luigi 'Comio' Mantellini01db1552009-10-10 12:42:21 +0200177#ifdef CONFIG_BITBANGMII
178 bb_miiphy_init();
179#endif
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +0900180#if defined(CONFIG_CMD_NET)
Mike Frysinger36fe7db2012-04-04 18:53:41 +0000181 puts("Net: ");
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500182 eth_initialize();
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +0900183#endif /* CONFIG_CMD_NET */
184
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900185 while (1) {
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +0900186 WATCHDOG_RESET();
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900187 main_loop();
188 }
189}