Do i2c init before serial init
[pandora-x-loader.git] / lib / board.c
1 /*
2  * Copyright (C) 2005 Texas Instruments.
3  *
4  * (C) Copyright 2004
5  * Jian Zhang, Texas Instruments, jzhang@ti.com.
6  *
7  * (C) Copyright 2002
8  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9  *
10  * (C) Copyright 2002
11  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12  * Marius Groeger <mgroeger@sysgo.de>
13  *
14  * See file CREDITS for list of people who contributed to this
15  * project.
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License as
19  * published by the Free Software Foundation; either version 2 of
20  * the License, or (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30  * MA 02111-1307 USA
31  */
32
33 #include <common.h>
34 #include <i2c.h>
35 #include <part.h>
36 #include <fat.h>
37 #include <asm/arch/mem.h>
38
39 const char version_string[] =
40         "Texas Instruments X-Loader 1.5.1 (" __DATE__ " - " __TIME__ ")";
41
42 int print_info(void)
43 {
44 #ifdef CFG_PRINTF
45         printf("\n\n%s\n", version_string);
46 #endif
47         return 0;
48 }
49
50 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
51 static int init_func_i2c (void)
52 {
53         i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
54         return 0;
55 }
56 #endif
57
58 typedef int (init_fnc_t) (void);
59
60 init_fnc_t *init_sequence[] = {
61         cpu_init,               /* basic cpu dependent setup */
62 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
63         init_func_i2c,
64 #endif
65         board_init,             /* basic board dependent setup */
66 #ifdef CFG_NS16550_SERIAL
67         serial_init,            /* serial communications setup */
68 #endif
69         print_info,
70         nand_init,              /* board specific nand init */
71         NULL,
72 };
73
74 void start_armboot (void)
75 {
76         init_fnc_t **init_fnc_ptr;
77         int size;
78         uchar *buf;
79         int *first_instruction;
80 #if defined(CFG_ONENAND) || defined(CFG_NAND_K9F1G08R0A)
81         int i;
82 #endif
83
84         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr)
85                 if ((*init_fnc_ptr)())
86                         hang ();
87
88         misc_init_r();
89
90         buf =  (uchar*) CFG_LOADADDR;
91         *(int *)buf = 0xffffffff;
92
93 #ifdef CONFIG_MMC
94         /* first try mmc */
95         if (mmc_init(1)) {
96                 size = file_fat_read("u-boot.bin", buf, 0);
97                 if (size > 0) {
98 #ifdef CFG_PRINTF
99                         printf("Loading u-boot.bin from mmc\n");
100 #endif
101                         buf += size;
102                 }
103         }
104 #endif
105
106         if (buf == (uchar *)CFG_LOADADDR) {
107                 /* if no u-boot on mmc, try onenand or nand, depending upon sysboot */
108                 if (get_mem_type() == GPMC_ONENAND){
109 #ifdef CFG_ONENAND
110 #ifdef CFG_PRINTF
111                         printf("Loading u-boot.bin from onenand\n");
112 #endif
113                         for (i = ONENAND_START_BLOCK; i < ONENAND_END_BLOCK; i++){
114                                 if (!onenand_read_block(buf, i))
115                                         buf += ONENAND_BLOCK_SIZE;
116                         }
117 #endif
118                 } else if (get_mem_type() == GPMC_NAND){
119 #ifdef CFG_NAND_K9F1G08R0A
120 #ifdef CFG_PRINTF
121                         printf("Loading u-boot.bin from nand\n");
122 #endif
123                         for (i = NAND_UBOOT_START; i < NAND_UBOOT_END; i+= NAND_BLOCK_SIZE){
124                                 if (!nand_read_block(buf, i))
125                                         buf += NAND_BLOCK_SIZE; /* advance buf ptr */
126                         }
127 #endif
128                 }
129         }
130
131         /* if u-boot not found on mmc or
132          * nand read result is erased data
133          * then serial boot 
134          */
135         first_instruction = (int *)CFG_LOADADDR;
136         if((buf == (uchar *)CFG_LOADADDR) || (*first_instruction == 0xffffffff)) {
137                 printf("u-boot.bin not found or blank nand contents - attempting serial boot . . .\n");
138                 do_load_serial_bin(CFG_LOADADDR, 115200);
139         }
140
141         /* go run U-Boot and never return */
142         ((init_fnc_t *)CFG_LOADADDR)();
143
144         /* should never come here */
145 }
146
147 void hang (void)
148 {
149         /* call board specific hang function */
150         board_hang();
151
152         /* if board_hang() returns, hang here */
153 #ifdef CFG_PRINTF
154         printf("X-Loader hangs\n");
155 #endif
156         for (;;);
157 }