Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
Heiko Schocher | af895e4 | 2011-02-22 08:58:19 +0100 | [diff] [blame] | 25 | #if defined(CONFIG_MGCOGE) || defined(CONFIG_MGCOGE2NE) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 26 | #include <mpc8260.h> |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 27 | #endif |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 28 | #include <ioports.h> |
| 29 | #include <malloc.h> |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 30 | #include <hush.h> |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 31 | #include <net.h> |
Heiko Schocher | 62ddcf0 | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 32 | #include <netdev.h> |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 33 | #include <asm/io.h> |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 34 | |
| 35 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 36 | #include <libfdt.h> |
| 37 | #endif |
| 38 | |
Heiko Schocher | 67fa8c2 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 39 | #include "../common/common.h" |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 40 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
| 41 | #include <i2c.h> |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 42 | |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 43 | static void i2c_write_start_seq(void); |
| 44 | static int i2c_make_abort(void); |
| 45 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 46 | int ivm_calc_crc(unsigned char *buf, int len) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 47 | { |
| 48 | const unsigned short crc_tab[16] = { |
| 49 | 0x0000, 0xCC01, 0xD801, 0x1400, |
| 50 | 0xF001, 0x3C00, 0x2800, 0xE401, |
| 51 | 0xA001, 0x6C00, 0x7800, 0xB401, |
| 52 | 0x5000, 0x9C01, 0x8801, 0x4400}; |
| 53 | |
| 54 | unsigned short crc = 0; /* final result */ |
| 55 | unsigned short r1 = 0; /* temp */ |
| 56 | unsigned char byte = 0; /* input buffer */ |
| 57 | int i; |
| 58 | |
| 59 | /* calculate CRC from array data */ |
| 60 | for (i = 0; i < len; i++) { |
| 61 | byte = buf[i]; |
| 62 | |
| 63 | /* lower 4 bits */ |
| 64 | r1 = crc_tab[crc & 0xF]; |
| 65 | crc = ((crc) >> 4) & 0x0FFF; |
| 66 | crc = crc ^ r1 ^ crc_tab[byte & 0xF]; |
| 67 | |
| 68 | /* upper 4 bits */ |
| 69 | r1 = crc_tab[crc & 0xF]; |
| 70 | crc = (crc >> 4) & 0x0FFF; |
| 71 | crc = crc ^ r1 ^ crc_tab[(byte >> 4) & 0xF]; |
| 72 | } |
| 73 | return crc; |
| 74 | } |
| 75 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 76 | static int ivm_set_value(char *name, char *value) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 77 | { |
| 78 | char tempbuf[256]; |
| 79 | |
| 80 | if (value != NULL) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 81 | sprintf(tempbuf, "%s=%s", name, value); |
| 82 | return set_local_var(tempbuf, 0); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 83 | } else { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 84 | unset_local_var(name); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 89 | static int ivm_get_value(unsigned char *buf, int len, char *name, int off, |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 90 | int check) |
| 91 | { |
| 92 | unsigned short val; |
| 93 | unsigned char valbuf[30]; |
| 94 | |
| 95 | if ((buf[off + 0] != buf[off + 2]) && |
| 96 | (buf[off + 2] != buf[off + 4])) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 97 | printf("%s Error corrupted %s\n", __func__, name); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 98 | val = -1; |
| 99 | } else { |
| 100 | val = buf[off + 0] + (buf[off + 1] << 8); |
| 101 | if ((val == 0) && (check == 1)) |
| 102 | val = -1; |
| 103 | } |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 104 | sprintf((char *)valbuf, "%x", val); |
| 105 | ivm_set_value(name, (char *)valbuf); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 106 | return val; |
| 107 | } |
| 108 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 109 | #define INV_BLOCKSIZE 0x100 |
| 110 | #define INV_DATAADDRESS 0x21 |
| 111 | #define INVENTORYDATASIZE (INV_BLOCKSIZE - INV_DATAADDRESS - 3) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 112 | |
| 113 | #define IVM_POS_SHORT_TEXT 0 |
| 114 | #define IVM_POS_MANU_ID 1 |
| 115 | #define IVM_POS_MANU_SERIAL 2 |
| 116 | #define IVM_POS_PART_NUMBER 3 |
| 117 | #define IVM_POS_BUILD_STATE 4 |
| 118 | #define IVM_POS_SUPPLIER_PART_NUMBER 5 |
| 119 | #define IVM_POS_DELIVERY_DATE 6 |
| 120 | #define IVM_POS_SUPPLIER_BUILD_STATE 7 |
| 121 | #define IVM_POS_CUSTOMER_ID 8 |
| 122 | #define IVM_POS_CUSTOMER_PROD_ID 9 |
| 123 | #define IVM_POS_HISTORY 10 |
| 124 | #define IVM_POS_SYMBOL_ONLY 11 |
| 125 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 126 | static char convert_char(char c) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 127 | { |
| 128 | return (c < ' ' || c > '~') ? '.' : c; |
| 129 | } |
| 130 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 131 | static int ivm_findinventorystring(int type, |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 132 | unsigned char* const string, |
| 133 | unsigned long maxlen, |
| 134 | unsigned char *buf) |
| 135 | { |
| 136 | int xcode = 0; |
| 137 | unsigned long cr = 0; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 138 | unsigned long addr = INV_DATAADDRESS; |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 139 | unsigned long size = 0; |
| 140 | unsigned long nr = type; |
| 141 | int stop = 0; /* stop on semicolon */ |
| 142 | |
| 143 | memset(string, '\0', maxlen); |
| 144 | switch (type) { |
| 145 | case IVM_POS_SYMBOL_ONLY: |
| 146 | nr = 0; |
| 147 | stop= 1; |
| 148 | break; |
| 149 | default: |
| 150 | nr = type; |
| 151 | stop = 0; |
| 152 | } |
| 153 | |
| 154 | /* Look for the requested number of CR. */ |
| 155 | while ((cr != nr) && (addr < INVENTORYDATASIZE)) { |
| 156 | if ((buf[addr] == '\r')) { |
| 157 | cr++; |
| 158 | } |
| 159 | addr++; |
| 160 | } |
| 161 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 162 | /* |
| 163 | * the expected number of CR was found until the end of the IVM |
| 164 | * content --> fill string |
| 165 | */ |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 166 | if (addr < INVENTORYDATASIZE) { |
| 167 | /* Copy the IVM string in the corresponding string */ |
| 168 | for (; (buf[addr] != '\r') && |
| 169 | ((buf[addr] != ';') || (!stop)) && |
| 170 | (size < (maxlen - 1) && |
| 171 | (addr < INVENTORYDATASIZE)); addr++) |
| 172 | { |
| 173 | size += sprintf((char *)string + size, "%c", |
| 174 | convert_char (buf[addr])); |
| 175 | } |
| 176 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 177 | /* |
| 178 | * copy phase is done: check if everything is ok. If not, |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 179 | * the inventory data is most probably corrupted: tell |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 180 | * the world there is a problem! |
| 181 | */ |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 182 | if (addr == INVENTORYDATASIZE) { |
| 183 | xcode = -1; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 184 | printf("Error end of string not found\n"); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 185 | } else if ((size >= (maxlen - 1)) && |
| 186 | (buf[addr] != '\r')) { |
| 187 | xcode = -1; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 188 | printf("string too long till next CR\n"); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 189 | } |
| 190 | } else { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 191 | /* |
| 192 | * some CR are missing... |
| 193 | * the inventory data is most probably corrupted |
| 194 | */ |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 195 | xcode = -1; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 196 | printf("not enough cr found\n"); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 197 | } |
| 198 | return xcode; |
| 199 | } |
| 200 | |
| 201 | #define GET_STRING(name, which, len) \ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 202 | if (ivm_findinventorystring(which, valbuf, len, buf) == 0) { \ |
| 203 | ivm_set_value(name, (char *)valbuf); \ |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 206 | static int ivm_check_crc(unsigned char *buf, int block) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 207 | { |
| 208 | unsigned long crc; |
| 209 | unsigned long crceeprom; |
| 210 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 211 | crc = ivm_calc_crc(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 212 | crceeprom = (buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 1] + \ |
| 213 | buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2] * 256); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 214 | if (crc != crceeprom) { |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 215 | if (block == 0) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 216 | printf("Error CRC Block: %d EEprom: calculated: \ |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 217 | %lx EEprom: %lx\n", block, crc, crceeprom); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 218 | return -1; |
| 219 | } |
| 220 | return 0; |
| 221 | } |
| 222 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 223 | static int ivm_analyze_block2(unsigned char *buf, int len) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 224 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 225 | unsigned char valbuf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN]; |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 226 | unsigned long count; |
| 227 | |
| 228 | /* IVM_MacAddress */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 229 | sprintf((char *)valbuf, "%pM", buf); |
| 230 | ivm_set_value("IVM_MacAddress", (char *)valbuf); |
Heiko Schocher | 0d01520 | 2011-01-06 10:25:26 +0100 | [diff] [blame^] | 231 | /* if an offset is defined, add it */ |
| 232 | #if defined(CONFIG_PIGGY_MAC_ADRESS_OFFSET) |
| 233 | if (CONFIG_PIGGY_MAC_ADRESS_OFFSET > 0) { |
| 234 | unsigned long val = (buf[4] << 16) + (buf[5] << 8) + buf[6]; |
| 235 | |
| 236 | val += CONFIG_PIGGY_MAC_ADRESS_OFFSET; |
| 237 | buf[4] = (val >> 16) & 0xff; |
| 238 | buf[5] = (val >> 8) & 0xff; |
| 239 | buf[6] = val & 0xff; |
| 240 | sprintf((char *)valbuf, "%pM", buf); |
| 241 | } |
| 242 | #endif |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 243 | if (getenv("ethaddr") == NULL) |
| 244 | setenv((char *)"ethaddr", (char *)valbuf); |
Heiko Schocher | 0d01520 | 2011-01-06 10:25:26 +0100 | [diff] [blame^] | 245 | |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 246 | /* IVM_MacCount */ |
| 247 | count = (buf[10] << 24) + |
| 248 | (buf[11] << 16) + |
| 249 | (buf[12] << 8) + |
| 250 | buf[13]; |
| 251 | if (count == 0xffffffff) |
| 252 | count = 1; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 253 | sprintf((char *)valbuf, "%lx", count); |
| 254 | ivm_set_value("IVM_MacCount", (char *)valbuf); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 258 | int ivm_analyze_eeprom(unsigned char *buf, int len) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 259 | { |
| 260 | unsigned short val; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 261 | unsigned char valbuf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN]; |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 262 | unsigned char *tmp; |
| 263 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 264 | if (ivm_check_crc(buf, 0) != 0) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 265 | return -1; |
| 266 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 267 | ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, |
| 268 | "IVM_BoardId", 0, 1); |
| 269 | val = ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, |
| 270 | "IVM_HWKey", 6, 1); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 271 | if (val != 0xffff) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 272 | sprintf((char *)valbuf, "%x", ((val / 100) % 10)); |
| 273 | ivm_set_value("IVM_HWVariant", (char *)valbuf); |
| 274 | sprintf((char *)valbuf, "%x", (val % 100)); |
| 275 | ivm_set_value("IVM_HWVersion", (char *)valbuf); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 276 | } |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 277 | ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, |
| 278 | "IVM_Functions", 12, 0); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 279 | |
| 280 | GET_STRING("IVM_Symbol", IVM_POS_SYMBOL_ONLY, 8) |
| 281 | GET_STRING("IVM_DeviceName", IVM_POS_SHORT_TEXT, 64) |
| 282 | tmp = (unsigned char *) getenv("IVM_DeviceName"); |
| 283 | if (tmp) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 284 | int len = strlen((char *)tmp); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 285 | int i = 0; |
| 286 | |
| 287 | while (i < len) { |
| 288 | if (tmp[i] == ';') { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 289 | ivm_set_value("IVM_ShortText", |
| 290 | (char *)&tmp[i + 1]); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 291 | break; |
| 292 | } |
| 293 | i++; |
| 294 | } |
| 295 | if (i >= len) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 296 | ivm_set_value("IVM_ShortText", NULL); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 297 | } else { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 298 | ivm_set_value("IVM_ShortText", NULL); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 299 | } |
| 300 | GET_STRING("IVM_ManufacturerID", IVM_POS_MANU_ID, 32) |
| 301 | GET_STRING("IVM_ManufacturerSerialNumber", IVM_POS_MANU_SERIAL, 20) |
| 302 | GET_STRING("IVM_ManufacturerPartNumber", IVM_POS_PART_NUMBER, 32) |
| 303 | GET_STRING("IVM_ManufacturerBuildState", IVM_POS_BUILD_STATE, 32) |
| 304 | GET_STRING("IVM_SupplierPartNumber", IVM_POS_SUPPLIER_PART_NUMBER, 32) |
| 305 | GET_STRING("IVM_DelieveryDate", IVM_POS_DELIVERY_DATE, 32) |
| 306 | GET_STRING("IVM_SupplierBuildState", IVM_POS_SUPPLIER_BUILD_STATE, 32) |
| 307 | GET_STRING("IVM_CustomerID", IVM_POS_CUSTOMER_ID, 32) |
| 308 | GET_STRING("IVM_CustomerProductID", IVM_POS_CUSTOMER_PROD_ID, 32) |
| 309 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 310 | if (ivm_check_crc(&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], 2) != 0) |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 311 | return 0; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 312 | ivm_analyze_block2(&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], |
| 313 | CONFIG_SYS_IVM_EEPROM_PAGE_LEN); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 318 | int ivm_read_eeprom(void) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 319 | { |
Heiko Schocher | 1b6275d | 2009-03-12 07:37:34 +0100 | [diff] [blame] | 320 | #if defined(CONFIG_I2C_MUX) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 321 | I2C_MUX_DEVICE *dev = NULL; |
Heiko Schocher | 1b6275d | 2009-03-12 07:37:34 +0100 | [diff] [blame] | 322 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 323 | uchar i2c_buffer[CONFIG_SYS_IVM_EEPROM_MAX_LEN]; |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 324 | uchar *buf; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 325 | unsigned dev_addr = CONFIG_SYS_IVM_EEPROM_ADR; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 326 | int ret; |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 327 | |
Heiko Schocher | 1b6275d | 2009-03-12 07:37:34 +0100 | [diff] [blame] | 328 | #if defined(CONFIG_I2C_MUX) |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 329 | /* First init the Bus, select the Bus */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 330 | #if defined(CONFIG_SYS_I2C_IVM_BUS) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 331 | dev = i2c_mux_ident_muxstring((uchar *)CONFIG_SYS_I2C_IVM_BUS); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 332 | #else |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 333 | buf = (unsigned char *) getenv("EEprom_ivm"); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 334 | if (buf != NULL) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 335 | dev = i2c_mux_ident_muxstring(buf); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 336 | #endif |
| 337 | if (dev == NULL) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 338 | printf("Error couldnt add Bus for IVM\n"); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 339 | return -1; |
| 340 | } |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 341 | i2c_set_bus_num(dev->busid); |
Heiko Schocher | 1b6275d | 2009-03-12 07:37:34 +0100 | [diff] [blame] | 342 | #endif |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 343 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 344 | buf = (unsigned char *) getenv("EEprom_ivm_addr"); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 345 | if (buf != NULL) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 346 | dev_addr = simple_strtoul((char *)buf, NULL, 16); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 347 | |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 348 | /* add deblocking here */ |
| 349 | i2c_make_abort(); |
| 350 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 351 | ret = i2c_read(dev_addr, 0, 1, i2c_buffer, |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 352 | CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 353 | if (ret != 0) { |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 354 | printf ("Error reading EEprom\n"); |
| 355 | return -2; |
| 356 | } |
| 357 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 358 | return ivm_analyze_eeprom(i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 361 | #if defined(CONFIG_SYS_I2C_INIT_BOARD) |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 362 | #define DELAY_ABORT_SEQ 62 /* @200kHz 9 clocks = 44us, 62us is ok */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 363 | #define DELAY_HALF_PERIOD (500 / (CONFIG_SYS_I2C_SPEED / 1000)) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 364 | |
Heiko Schocher | af895e4 | 2011-02-22 08:58:19 +0100 | [diff] [blame] | 365 | #if defined(CONFIG_MGCOGE) || defined(CONFIG_MGCOGE2NE) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 366 | #define SDA_MASK 0x00010000 |
| 367 | #define SCL_MASK 0x00020000 |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 368 | static void set_pin(int state, unsigned long mask) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 369 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 370 | ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 371 | |
| 372 | if (state) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 373 | setbits_be32(&iop->pdat, mask); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 374 | else |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 375 | clrbits_be32(&iop->pdat, mask); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 376 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 377 | setbits_be32(&iop->pdir, mask); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 378 | } |
| 379 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 380 | static int get_pin(unsigned long mask) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 381 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 382 | ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 383 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 384 | clrbits_be32(&iop->pdir, mask); |
| 385 | return 0 != (in_be32(&iop->pdat) & mask); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 388 | static void set_sda(int state) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 389 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 390 | set_pin(state, SDA_MASK); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 391 | } |
| 392 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 393 | static void set_scl(int state) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 394 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 395 | set_pin(state, SCL_MASK); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 396 | } |
| 397 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 398 | static int get_sda(void) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 399 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 400 | return get_pin(SDA_MASK); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 403 | static int get_scl(void) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 404 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 405 | return get_pin(SCL_MASK); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | #if defined(CONFIG_HARD_I2C) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 409 | static void setports(int gpio) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 410 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 411 | ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 412 | |
| 413 | if (gpio) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 414 | clrbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK)); |
| 415 | clrbits_be32(&iop->podr, (SDA_MASK | SCL_MASK)); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 416 | } else { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 417 | setbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK)); |
| 418 | clrbits_be32(&iop->pdir, (SDA_MASK | SCL_MASK)); |
| 419 | setbits_be32(&iop->podr, (SDA_MASK | SCL_MASK)); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | #endif |
| 423 | #endif |
| 424 | |
Heiko Schocher | 62ddcf0 | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 425 | #if !defined(CONFIG_MPC83xx) |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 426 | static void i2c_write_start_seq(void) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 427 | { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 428 | set_sda(1); |
| 429 | udelay(DELAY_HALF_PERIOD); |
| 430 | set_scl(1); |
| 431 | udelay(DELAY_HALF_PERIOD); |
| 432 | set_sda(0); |
| 433 | udelay(DELAY_HALF_PERIOD); |
| 434 | set_scl(0); |
| 435 | udelay(DELAY_HALF_PERIOD); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 438 | /* |
| 439 | * I2C is a synchronous protocol and resets of the processor in the middle |
| 440 | * of an access can block the I2C Bus until a powerdown of the full unit is |
| 441 | * done. This function toggles the SCL until the SCL and SCA line are |
| 442 | * released, but max. 16 times, after this a I2C start-sequence is sent. |
| 443 | * This I2C Deblocking mechanism was developed by Keymile in association |
| 444 | * with Anatech and Atmel in 1998. |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 445 | */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 446 | static int i2c_make_abort(void) |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 447 | { |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 448 | |
| 449 | #if defined(CONFIG_HARD_I2C) && !defined(MACH_TYPE_KM_KIRKWOOD) |
| 450 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR ; |
| 451 | i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c; |
| 452 | |
| 453 | /* |
| 454 | * disable I2C controller first, otherwhise it thinks we want to |
| 455 | * talk to the slave port... |
| 456 | */ |
| 457 | clrbits_8(&i2c->i2c_i2mod, 0x01); |
| 458 | |
| 459 | /* Set the PortPins to GPIO */ |
| 460 | setports(1); |
| 461 | #endif |
| 462 | |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 463 | int scl_state = 0; |
| 464 | int sda_state = 0; |
| 465 | int i = 0; |
| 466 | int ret = 0; |
| 467 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 468 | if (!get_sda()) { |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 469 | ret = -1; |
| 470 | while (i < 16) { |
| 471 | i++; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 472 | set_scl(0); |
| 473 | udelay(DELAY_ABORT_SEQ); |
| 474 | set_scl(1); |
| 475 | udelay(DELAY_ABORT_SEQ); |
| 476 | scl_state = get_scl(); |
| 477 | sda_state = get_sda(); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 478 | if (scl_state && sda_state) { |
| 479 | ret = 0; |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | } |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 484 | if (ret == 0) |
| 485 | for (i = 0; i < 5; i++) |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 486 | i2c_write_start_seq(); |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 487 | |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 488 | /* respect stop setup time */ |
| 489 | udelay(DELAY_ABORT_SEQ); |
| 490 | set_scl(1); |
| 491 | udelay(DELAY_ABORT_SEQ); |
| 492 | set_sda(1); |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 493 | get_sda(); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 494 | |
| 495 | #if defined(CONFIG_HARD_I2C) |
| 496 | /* Set the PortPins back to use for I2C */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 497 | setports(0); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 498 | #endif |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 499 | return ret; |
| 500 | } |
Heiko Schocher | 39df00d | 2009-07-09 12:04:26 +0200 | [diff] [blame] | 501 | #endif |
Heiko Schocher | 6c11aea | 2011-03-08 10:51:15 +0100 | [diff] [blame] | 502 | |
| 503 | #if defined(CONFIG_MPC83xx) |
| 504 | static void i2c_write_start_seq(void) |
| 505 | { |
| 506 | struct fsl_i2c *dev; |
| 507 | dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET); |
| 508 | udelay(DELAY_ABORT_SEQ); |
| 509 | out_8(&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA)); |
| 510 | udelay(DELAY_ABORT_SEQ); |
| 511 | out_8(&dev->cr, (I2C_CR_MEN)); |
| 512 | } |
| 513 | |
| 514 | static int i2c_make_abort(void) |
| 515 | { |
| 516 | struct fsl_i2c *dev; |
| 517 | dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET); |
| 518 | uchar dummy; |
| 519 | uchar last; |
| 520 | int nbr_read = 0; |
| 521 | int i = 0; |
| 522 | int ret = 0; |
| 523 | |
| 524 | /* wait after each operation to finsh with a delay */ |
| 525 | out_8(&dev->cr, (I2C_CR_MSTA)); |
| 526 | udelay(DELAY_ABORT_SEQ); |
| 527 | out_8(&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA)); |
| 528 | udelay(DELAY_ABORT_SEQ); |
| 529 | dummy = in_8(&dev->dr); |
| 530 | udelay(DELAY_ABORT_SEQ); |
| 531 | last = in_8(&dev->dr); |
| 532 | nbr_read++; |
| 533 | |
| 534 | /* |
| 535 | * do read until the last bit is 1, but stop if the full eeprom is |
| 536 | * read. |
| 537 | */ |
| 538 | while (((last & 0x01) != 0x01) && |
| 539 | (nbr_read < CONFIG_SYS_IVM_EEPROM_MAX_LEN)) { |
| 540 | udelay(DELAY_ABORT_SEQ); |
| 541 | last = in_8(&dev->dr); |
| 542 | nbr_read++; |
| 543 | } |
| 544 | if ((last & 0x01) != 0x01) |
| 545 | ret = -2; |
| 546 | if ((last != 0xff) || (nbr_read > 1)) |
| 547 | printf("[INFO] i2c abort after %d bytes (0x%02x)\n", |
| 548 | nbr_read, last); |
| 549 | udelay(DELAY_ABORT_SEQ); |
| 550 | out_8(&dev->cr, (I2C_CR_MEN)); |
| 551 | udelay(DELAY_ABORT_SEQ); |
| 552 | /* clear status reg */ |
| 553 | out_8(&dev->sr, 0); |
| 554 | |
| 555 | for (i = 0; i < 5; i++) |
| 556 | i2c_write_start_seq(); |
| 557 | if (ret != 0) |
| 558 | printf("[ERROR] i2c abort failed after %d bytes (0x%02x)\n", |
| 559 | nbr_read, last); |
| 560 | |
| 561 | return ret; |
| 562 | } |
| 563 | #endif |
| 564 | |
| 565 | /** |
| 566 | * i2c_init_board - reset i2c bus. When the board is powercycled during a |
| 567 | * bus transfer it might hang; for details see doc/I2C_Edge_Conditions. |
| 568 | */ |
| 569 | void i2c_init_board(void) |
| 570 | { |
| 571 | /* Now run the AbortSequence() */ |
| 572 | i2c_make_abort(); |
Heiko Schocher | c248536 | 2008-10-15 09:39:08 +0200 | [diff] [blame] | 573 | } |
| 574 | #endif |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 575 | #endif |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 576 | |
| 577 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 578 | int fdt_set_node_and_value(void *blob, |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 579 | char *nodename, |
| 580 | char *regname, |
| 581 | void *var, |
| 582 | int size) |
| 583 | { |
| 584 | int ret = 0; |
| 585 | int nodeoffset = 0; |
| 586 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 587 | nodeoffset = fdt_path_offset(blob, nodename); |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 588 | if (nodeoffset >= 0) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 589 | ret = fdt_setprop(blob, nodeoffset, regname, var, |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 590 | size); |
| 591 | if (ret < 0) |
| 592 | printf("ft_blob_update(): cannot set %s/%s " |
| 593 | "property err:%s\n", nodename, regname, |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 594 | fdt_strerror(ret)); |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 595 | } else { |
| 596 | printf("ft_blob_update(): cannot find %s node " |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 597 | "err:%s\n", nodename, fdt_strerror(nodeoffset)); |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 598 | } |
| 599 | return ret; |
| 600 | } |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 601 | |
| 602 | int fdt_get_node_and_value(void *blob, |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 603 | char *nodename, |
| 604 | char *propname, |
| 605 | void **var) |
| 606 | { |
| 607 | int len; |
| 608 | int nodeoffset = 0; |
| 609 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 610 | nodeoffset = fdt_path_offset(blob, nodename); |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 611 | if (nodeoffset >= 0) { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 612 | *var = (void *)fdt_getprop(blob, nodeoffset, propname, &len); |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 613 | if (len == 0) { |
| 614 | /* no value */ |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 615 | printf("%s no value\n", __func__); |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 616 | return -1; |
| 617 | } else if (len > 0) { |
| 618 | return len; |
| 619 | } else { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 620 | printf("libfdt fdt_getprop(): %s\n", |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 621 | fdt_strerror(len)); |
| 622 | return -2; |
| 623 | } |
| 624 | } else { |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 625 | printf("%s: cannot find %s node err:%s\n", __func__, |
| 626 | nodename, fdt_strerror(nodeoffset)); |
Heiko Schocher | dc71b24 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 627 | return -3; |
| 628 | } |
| 629 | } |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 630 | #endif |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 631 | |
Holger Brunck | 802d996 | 2011-03-14 15:31:19 +0100 | [diff] [blame] | 632 | #if !defined(MACH_TYPE_KM_KIRKWOOD) |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 633 | int ethernet_present(void) |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 634 | { |
Heiko Schocher | 8ed7434 | 2011-03-08 10:47:39 +0100 | [diff] [blame] | 635 | struct km_bec_fpga *base = |
| 636 | (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE; |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 637 | |
| 638 | return in_8(&base->bprth) & PIGGY_PRESENT; |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 639 | } |
Heiko Schocher | 67fa8c2 | 2010-02-22 16:43:02 +0530 | [diff] [blame] | 640 | #endif |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 641 | |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 642 | int board_eth_init(bd_t *bis) |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 643 | { |
| 644 | #ifdef CONFIG_KEYMILE_HDLC_ENET |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 645 | (void)keymile_hdlc_enet_initialize(bis); |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 646 | #endif |
Heiko Schocher | b11f53f | 2011-03-15 16:52:29 +0100 | [diff] [blame] | 647 | if (ethernet_present()) |
Heiko Schocher | 62ddcf0 | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 648 | return cpu_eth_init(bis); |
| 649 | |
| 650 | return -1; |
Heiko Schocher | 210c8c0 | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 651 | } |