blob: 55e24a8f92b10c597fc99bfebc7cc7ce4e7019f7 [file] [log] [blame]
Chandan Nath5289e832011-10-14 02:58:26 +00001/*
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>
Ilya Yanokc59a6a02012-07-24 12:22:19 +000017#include <errno.h>
Chandan Nath5289e832011-10-14 02:58:26 +000018#include <asm/arch/cpu.h>
19#include <asm/arch/hardware.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000020#include <asm/arch/common_def.h>
Patil, Rachnab4116ed2012-01-22 23:47:01 +000021#include <i2c.h>
Chandan Nath5289e832011-10-14 02:58:26 +000022
23DECLARE_GLOBAL_DATA_PTR;
24
Chandan Nath5289e832011-10-14 02:58:26 +000025/*
Ilya Yanokc59a6a02012-07-24 12:22:19 +000026 * 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
35struct 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
44static struct am335x_baseboard_id header;
45
46static 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 */
54int 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/*
Chandan Nath5289e832011-10-14 02:58:26 +000093 * Basic board specific setup
94 */
Chandan Nath5289e832011-10-14 02:58:26 +000095int board_init(void)
96{
97 enable_uart0_pin_mux();
Patil, Rachnab4116ed2012-01-22 23:47:01 +000098
Patil, Rachnab4116ed2012-01-22 23:47:01 +000099 enable_i2c0_pin_mux();
Steve Sakomand3decde2012-06-22 07:45:57 +0000100 enable_i2c1_pin_mux();
Patil, Rachnab4116ed2012-01-22 23:47:01 +0000101 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Ilya Yanokc59a6a02012-07-24 12:22:19 +0000102 if (read_eeprom() < 0)
103 printf("Could not get board ID.\n");
Patil, Rachnab4116ed2012-01-22 23:47:01 +0000104
Tom Rini2ab28102012-05-14 12:38:18 +0000105 gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
Chandan Nath5289e832011-10-14 02:58:26 +0000106
107 return 0;
108}