blob: 69cdca3744f9cd72f2bdfa449e7b0ed63a65d264 [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>
Simon Glass24b852a2015-11-08 23:47:45 -070010#include <console.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090011#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020012#include <stdio_dev.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090013#include <version.h>
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090014#include <watchdog.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090015#include <net.h>
Nobuhiro Iwamatsue1bc28f2012-03-21 14:48:34 +090016#include <mmc.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090017#include <environment.h>
18
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +020019#ifdef CONFIG_BITBANGMII
20#include <miiphy.h>
21#endif
22
John Rigby29565322010-12-20 18:27:51 -070023DECLARE_GLOBAL_DATA_PTR;
24
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090025extern int cpu_init(void);
26extern int board_init(void);
27extern int dram_init(void);
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090028extern int timer_init(void);
29
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020030unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090031
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +090032#ifndef CONFIG_SYS_NO_FLASH
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090033static int sh_flash_init(void)
34{
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090035 gd->bd->bi_flashsize = flash_init();
Nobuhiro Iwamatsuc4176c42010-10-26 20:23:53 +090036
37 if (gd->bd->bi_flashsize >= (1024 * 1024))
Peter Tysereddf52b2010-12-28 18:12:05 -060038 printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
Nobuhiro Iwamatsuc4176c42010-10-26 20:23:53 +090039 else
Peter Tysereddf52b2010-12-28 18:12:05 -060040 printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090041
42 return 0;
43}
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +090044#endif /* CONFIG_SYS_NO_FLASH */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090045
46#if defined(CONFIG_CMD_NAND)
Nobuhiro Iwamatsu4a065ab2008-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 Iwamatsub02bad12007-09-23 02:12:30 +090051#endif /* CONFIG_CMD_NAND */
52
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090053#if defined(CONFIG_WATCHDOG)
54extern int watchdog_init(void);
55extern int watchdog_disable(void);
Simon Glassa6741bc2013-03-05 14:39:42 +000056# undef INIT_FUNC_WATCHDOG_INIT
Nobuhiro Iwamatsu4a065ab2008-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 Iwamatsub02bad12007-09-23 02:12:30 +090064#if defined(CONFIG_CMD_IDE)
Nobuhiro Iwamatsu4a065ab2008-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 Iwamatsub02bad12007-09-23 02:12:30 +090070
Yusuke Goda1a2334a2008-03-05 14:30:02 +090071#if defined(CONFIG_PCI)
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090072#include <pci.h>
Yusuke Goda1a2334a2008-03-05 14:30:02 +090073static int sh_pci_init(void)
74{
75 pci_init();
76 return 0;
77}
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +090078# define INIT_FUNC_PCI_INIT sh_pci_init,
79#else
80# define INIT_FUNC_PCI_INIT
Yusuke Goda1a2334a2008-03-05 14:30:02 +090081#endif /* CONFIG_PCI */
82
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090083static int sh_mem_env_init(void)
84{
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020085 mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
Peter Tysera483a162009-08-21 23:05:20 -050086 CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090087 env_relocate();
88 jumptable_init();
89 return 0;
90}
91
Yoshihiro Shimodafe0ddff2011-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 Iwamatsu0b135cf2007-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 Iwamatsu4a065ab2008-09-18 19:04:26 +0900107 interrupt_init, /* set up exceptions */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900108 env_init, /* event init */
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900109 serial_init, /* SCIF init */
110 INIT_FUNC_WATCHDOG_INIT /* watchdog init */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900111 console_init_f,
112 display_options,
113 checkcpu,
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900114 checkboard, /* Check support board */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900115 dram_init, /* SDRAM init */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900116 timer_init, /* SuperH Timer (TCNT0 only) init */
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900117 sh_mem_env_init,
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +0900118#ifndef CONFIG_SYS_NO_FLASH
119 sh_flash_init, /* Flash memory init*/
120#endif
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900121 INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
122 INIT_FUNC_PCI_INIT /* PCI init */
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200123 stdio_init,
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900124 console_init_r,
125 interrupt_init,
Helmut Raiger9660e442011-10-20 04:19:47 +0000126#ifdef CONFIG_BOARD_LATE_INIT
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900127 board_late_init,
128#endif
Yoshihiro Shimodafe0ddff2011-07-05 17:18:38 +0900129#if defined(CONFIG_CMD_MMC)
130 sh_mmc_init,
131#endif
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900132 NULL /* Terminate this list */
133};
134
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900135void sh_generic_init(void)
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900136{
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900137 bd_t *bd;
138 init_fnc_t **init_fnc_ptr;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900139
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +0200140 memset(gd, 0, GENERATED_GBL_DATA_SIZE);
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900141
142 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
143
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900144 gd->bd = (bd_t *)(gd + 1); /* At end of global data */
Nobuhiro Iwamatsu0b135cf2007-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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200150 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
151 bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +0900152#ifndef CONFIG_SYS_NO_FLASH
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200153 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
Nobuhiro Iwamatsu40c47702011-03-07 11:21:40 +0900154#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-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 Iwamatsu0b135cf2007-05-13 20:58:00 +0900158#endif
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900159
Nobuhiro Iwamatsu4a065ab2008-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 Iwamatsu0b135cf2007-05-13 20:58:00 +0900163 hang();
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900164 }
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900165
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900166#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();
173 }
174#endif /* CONFIG_WATCHDOG*/
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900175
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900176
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200177#ifdef CONFIG_BITBANGMII
178 bb_miiphy_init();
179#endif
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900180#if defined(CONFIG_CMD_NET)
Mike Frysingerde301222012-04-04 18:53:41 +0000181 puts("Net: ");
Joe Hershbergerd2eaec62015-03-22 17:09:06 -0500182 eth_initialize();
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +0900183#endif /* CONFIG_CMD_NET */
184
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900185 while (1) {
Nobuhiro Iwamatsu4a065ab2008-09-18 19:04:26 +0900186 WATCHDOG_RESET();
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900187 main_loop();
188 }
189}