blob: 6dad3c7dbfefcd400daabd34714062ed94d96516 [file] [log] [blame]
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +09001/*
Nobuhiro Iwamatsuc4176c42010-10-26 20:23:53 +09002 * Copyright (C) 2007, 2008, 2010
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +09003 * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +09006 */
7
8#include <common.h>
9#include <command.h>
10#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020011#include <stdio_dev.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090012#include <version.h>
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090013#include <watchdog.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090014#include <net.h>
Nobuhiro Iwamatsue1bc28f2012-03-21 14:48:34 +090015#include <mmc.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090016#include <environment.h>
17
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +020018#ifdef CONFIG_BITBANGMII
19#include <miiphy.h>
20#endif
21
John Rigby29565322010-12-20 18:27:51 -070022DECLARE_GLOBAL_DATA_PTR;
23
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090024extern int cpu_init(void);
25extern int board_init(void);
26extern int dram_init(void);
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090027extern int timer_init(void);
28
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020029unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090030
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +090031#ifndef CONFIG_SYS_NO_FLASH
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090032static int sh_flash_init(void)
33{
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090034 gd->bd->bi_flashsize = flash_init();
Nobuhiro Iwamatsuc4176c42010-10-26 20:23:53 +090035
36 if (gd->bd->bi_flashsize >= (1024 * 1024))
Peter Tysereddf52b2010-12-28 18:12:05 -060037 printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
Nobuhiro Iwamatsuc4176c42010-10-26 20:23:53 +090038 else
Peter Tysereddf52b2010-12-28 18:12:05 -060039 printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090040
41 return 0;
42}
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +090043#endif /* CONFIG_SYS_NO_FLASH */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090044
45#if defined(CONFIG_CMD_NAND)
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090046# include <nand.h>
47# define INIT_FUNC_NAND_INIT nand_init,
48#else
49# define INIT_FUNC_NAND_INIT
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090050#endif /* CONFIG_CMD_NAND */
51
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090052#if defined(CONFIG_WATCHDOG)
53extern int watchdog_init(void);
54extern int watchdog_disable(void);
Simon Glassa6741bc2013-03-05 14:39:42 +000055# undef INIT_FUNC_WATCHDOG_INIT
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090056# define INIT_FUNC_WATCHDOG_INIT watchdog_init,
57# define WATCHDOG_DISABLE watchdog_disable
58#else
59# define INIT_FUNC_WATCHDOG_INIT
60# define WATCHDOG_DISABLE
61#endif /* CONFIG_WATCHDOG */
62
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090063#if defined(CONFIG_CMD_IDE)
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090064# include <ide.h>
65# define INIT_FUNC_IDE_INIT ide_init,
66#else
67# define INIT_FUNC_IDE_INIT
68#endif /* CONFIG_CMD_IDE */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090069
Yusuke Goda1a2334a2008-03-05 14:30:02 +090070#if defined(CONFIG_PCI)
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090071#include <pci.h>
Yusuke Goda1a2334a2008-03-05 14:30:02 +090072static int sh_pci_init(void)
73{
74 pci_init();
75 return 0;
76}
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090077# define INIT_FUNC_PCI_INIT sh_pci_init,
78#else
79# define INIT_FUNC_PCI_INIT
Yusuke Goda1a2334a2008-03-05 14:30:02 +090080#endif /* CONFIG_PCI */
81
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090082static int sh_mem_env_init(void)
83{
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020084 mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
Peter Tysera483a162009-08-21 23:05:20 -050085 CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090086 env_relocate();
87 jumptable_init();
88 return 0;
89}
90
Yoshihiro Shimodafe0ddff2011-07-05 17:18:38 +090091#if defined(CONFIG_CMD_MMC)
92static int sh_mmc_init(void)
93{
94 puts("MMC: ");
95 mmc_initialize(gd->bd);
96 return 0;
97}
98#endif
99
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900100typedef int (init_fnc_t) (void);
101
102init_fnc_t *init_sequence[] =
103{
104 cpu_init, /* basic cpu dependent setup */
105 board_init, /* basic board dependent setup */
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900106 interrupt_init, /* set up exceptions */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900107 env_init, /* event init */
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900108 serial_init, /* SCIF init */
109 INIT_FUNC_WATCHDOG_INIT /* watchdog init */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900110 console_init_f,
111 display_options,
112 checkcpu,
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900113 checkboard, /* Check support board */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900114 dram_init, /* SDRAM init */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900115 timer_init, /* SuperH Timer (TCNT0 only) init */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900116 sh_mem_env_init,
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +0900117#ifndef CONFIG_SYS_NO_FLASH
118 sh_flash_init, /* Flash memory init*/
119#endif
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900120 INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
121 INIT_FUNC_PCI_INIT /* PCI init */
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200122 stdio_init,
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900123 console_init_r,
124 interrupt_init,
Helmut Raiger9660e442011-10-20 04:19:47 +0000125#ifdef CONFIG_BOARD_LATE_INIT
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900126 board_late_init,
127#endif
Yoshihiro Shimodafe0ddff2011-07-05 17:18:38 +0900128#if defined(CONFIG_CMD_MMC)
129 sh_mmc_init,
130#endif
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900131 NULL /* Terminate this list */
132};
133
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900134void sh_generic_init(void)
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900135{
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900136 bd_t *bd;
137 init_fnc_t **init_fnc_ptr;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900138
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +0200139 memset(gd, 0, GENERATED_GBL_DATA_SIZE);
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900140
141 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
142
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900143 gd->bd = (bd_t *)(gd + 1); /* At end of global data */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900144 gd->baudrate = CONFIG_BAUDRATE;
145
146 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
147
148 bd = gd->bd;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
150 bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +0900151#ifndef CONFIG_SYS_NO_FLASH
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200152 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +0900153#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200154#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
155 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
156 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900157#endif
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900158
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900159 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
160 WATCHDOG_RESET();
161 if ((*init_fnc_ptr) () != 0)
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900162 hang();
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900163 }
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900164
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900165#ifdef CONFIG_WATCHDOG
166 /* disable watchdog if environment is set */
167 {
168 char *s = getenv("watchdog");
169 if (s != NULL)
170 if (strncmp(s, "off", 3) == 0)
171 WATCHDOG_DISABLE();
172 }
173#endif /* CONFIG_WATCHDOG*/
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900174
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900175
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200176#ifdef CONFIG_BITBANGMII
177 bb_miiphy_init();
178#endif
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900179#if defined(CONFIG_CMD_NET)
Mike Frysingerde301222012-04-04 18:53:41 +0000180 puts("Net: ");
Joe Hershbergerd2eaec62015-03-22 17:09:06 -0500181 eth_initialize();
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900182#endif /* CONFIG_CMD_NET */
183
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900184 while (1) {
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900185 WATCHDOG_RESET();
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900186 main_loop();
187 }
188}