]> git.sur5r.net Git - u-boot/blob - board/ti/am335x/evm.c
55e24a8f92b10c597fc99bfebc7cc7ce4e7019f7
[u-boot] / board / ti / am335x / evm.c
1 /*
2  * evm.c
3  *
4  * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation version 2.
9  *
10  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11  * kind, whether express or implied; without even the implied warranty
12  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  */
15
16 #include <common.h>
17 #include <errno.h>
18 #include <asm/arch/cpu.h>
19 #include <asm/arch/hardware.h>
20 #include <asm/arch/common_def.h>
21 #include <i2c.h>
22
23 DECLARE_GLOBAL_DATA_PTR;
24
25 /*
26  * I2C Address of on-board EEPROM
27  */
28 #define I2C_BASE_BOARD_ADDR     0x50
29
30 #define NO_OF_MAC_ADDR          3
31 #define ETH_ALEN                6
32
33 #define NAME_LEN        8
34
35 struct am335x_baseboard_id {
36         unsigned int  magic;
37         char name[NAME_LEN];
38         char version[4];
39         char serial[12];
40         char config[32];
41         char mac_addr[NO_OF_MAC_ADDR][ETH_ALEN];
42 };
43
44 static struct am335x_baseboard_id header;
45
46 static inline int board_is_bone(void)
47 {
48         return !strncmp(header.name, "A335BONE", NAME_LEN);
49 }
50
51 /*
52  * Read header information from EEPROM into global structure.
53  */
54 int read_eeprom(void)
55 {
56         /* Check if baseboard eeprom is available */
57         if (i2c_probe(I2C_BASE_BOARD_ADDR)) {
58                 printf("Could not probe the EEPROM; something fundamentally "
59                         "wrong on the I2C bus.\n");
60                 return -ENODEV;
61         }
62
63         /* read the eeprom using i2c */
64         if (i2c_read(I2C_BASE_BOARD_ADDR, 0, 2, (uchar *)&header,
65                                                         sizeof(header))) {
66                 printf("Could not read the EEPROM; something fundamentally"
67                         " wrong on the I2C bus.\n");
68                 return -EIO;
69         }
70
71         if (header.magic != 0xEE3355AA) {
72                 /*
73                  * read the eeprom using i2c again,
74                  * but use only a 1 byte address
75                  */
76                 if (i2c_read(I2C_BASE_BOARD_ADDR, 0, 1, (uchar *)&header,
77                                                         sizeof(header))) {
78                         printf("Could not read the EEPROM; something "
79                                 "fundamentally wrong on the I2C bus.\n");
80                         return -EIO;
81                 }
82
83                 if (header.magic != 0xEE3355AA) {
84                         printf("Incorrect magic number in EEPROM\n");
85                         return -EINVAL;
86                 }
87         }
88
89         return 0;
90 }
91
92 /*
93  * Basic board specific setup
94  */
95 int board_init(void)
96 {
97         enable_uart0_pin_mux();
98
99         enable_i2c0_pin_mux();
100         enable_i2c1_pin_mux();
101         i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
102         if (read_eeprom() < 0)
103                 printf("Could not get board ID.\n");
104
105         gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
106
107         return 0;
108 }