Chandan Nath | 5289e83 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 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> |
Ilya Yanok | c59a6a0 | 2012-07-24 12:22:19 +0000 | [diff] [blame^] | 17 | #include <errno.h> |
Chandan Nath | 5289e83 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 18 | #include <asm/arch/cpu.h> |
| 19 | #include <asm/arch/hardware.h> |
Chandan Nath | 8a8f084 | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 20 | #include <asm/arch/common_def.h> |
Patil, Rachna | b4116ed | 2012-01-22 23:47:01 +0000 | [diff] [blame] | 21 | #include <i2c.h> |
Chandan Nath | 5289e83 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Chandan Nath | 5289e83 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 25 | /* |
Ilya Yanok | c59a6a0 | 2012-07-24 12:22:19 +0000 | [diff] [blame^] | 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 | /* |
Chandan Nath | 5289e83 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 93 | * Basic board specific setup |
| 94 | */ |
Chandan Nath | 5289e83 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 95 | int board_init(void) |
| 96 | { |
| 97 | enable_uart0_pin_mux(); |
Patil, Rachna | b4116ed | 2012-01-22 23:47:01 +0000 | [diff] [blame] | 98 | |
Patil, Rachna | b4116ed | 2012-01-22 23:47:01 +0000 | [diff] [blame] | 99 | enable_i2c0_pin_mux(); |
Steve Sakoman | d3decde | 2012-06-22 07:45:57 +0000 | [diff] [blame] | 100 | enable_i2c1_pin_mux(); |
Patil, Rachna | b4116ed | 2012-01-22 23:47:01 +0000 | [diff] [blame] | 101 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
Ilya Yanok | c59a6a0 | 2012-07-24 12:22:19 +0000 | [diff] [blame^] | 102 | if (read_eeprom() < 0) |
| 103 | printf("Could not get board ID.\n"); |
Patil, Rachna | b4116ed | 2012-01-22 23:47:01 +0000 | [diff] [blame] | 104 | |
Tom Rini | 2ab2810 | 2012-05-14 12:38:18 +0000 | [diff] [blame] | 105 | gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100; |
Chandan Nath | 5289e83 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 106 | |
| 107 | return 0; |
| 108 | } |