wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com. |
| 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 | #if defined(VXWORKS) |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | #define CONFIG_SYS_DEF_EEPROM_ADDR 0xa0 |
| 28 | extern char iicReadByte(char, char); |
| 29 | extern ulong_t crc32(unsigned char *, unsigned long); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | #else |
| 31 | #include <common.h> |
| 32 | #endif |
| 33 | |
| 34 | #include "vpd.h" |
| 35 | |
| 36 | /* |
| 37 | * vpd_reader() - reads VPD data from I2C EEPROMS. |
| 38 | * returns pointer to buffer or NULL. |
| 39 | */ |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 40 | static unsigned char *vpd_reader(unsigned char *buf, unsigned dev_addr, |
| 41 | unsigned off, unsigned count) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 42 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 43 | unsigned offset = off; /* Calculated offset */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 45 | /* |
| 46 | * The main board EEPROM contains |
| 47 | * SDRAM SPD in the first 128 bytes, |
| 48 | * so skew the offset. |
| 49 | */ |
| 50 | if (dev_addr == CONFIG_SYS_DEF_EEPROM_ADDR) |
| 51 | offset += SDRAM_SPD_DATA_SIZE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 52 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 53 | /* Try to read the I2C EEPROM */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | #if defined(VXWORKS) |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 55 | { |
| 56 | int i; |
| 57 | |
| 58 | for (i = 0; i < count; ++i) |
| 59 | buf[i] = iicReadByte(dev_addr, offset + i); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 60 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 61 | #else |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 62 | if (eeprom_read(dev_addr, offset, buf, count)) { |
| 63 | printf("Failed to read %d bytes from VPD EEPROM 0x%x @ 0x%x\n", |
| 64 | count, dev_addr, offset); |
| 65 | return NULL; |
| 66 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 69 | return buf; |
| 70 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 71 | |
| 72 | |
| 73 | /* |
| 74 | * vpd_get_packet() - returns next VPD packet or NULL. |
| 75 | */ |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 76 | static vpd_packet_t *vpd_get_packet(vpd_packet_t * vpd_packet) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 77 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 78 | vpd_packet_t *packet = vpd_packet; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 79 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 80 | if (packet != NULL) { |
| 81 | if (packet->identifier == VPD_PID_TERM) |
| 82 | return NULL; |
| 83 | else |
| 84 | packet = (vpd_packet_t *) ((char *) packet + |
| 85 | packet->size + 2); |
| 86 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 87 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 88 | return packet; |
| 89 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 90 | |
| 91 | |
| 92 | /* |
| 93 | * vpd_find_packet() - Locates and returns the specified |
| 94 | * VPD packet or NULL on error. |
| 95 | */ |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 96 | static vpd_packet_t *vpd_find_packet(vpd_t * vpd, unsigned char ident) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 97 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 98 | vpd_packet_t *packet = (vpd_packet_t *) &vpd->packets; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 100 | /* Guaranteed illegal */ |
| 101 | if (ident == VPD_PID_GI) |
| 102 | return NULL; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 104 | /* Scan tuples looking for a match */ |
| 105 | while ((packet->identifier != ident) && |
| 106 | (packet->identifier != VPD_PID_TERM)) |
| 107 | packet = vpd_get_packet(packet); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 108 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 109 | /* Did we find it? */ |
| 110 | if ((packet->identifier) && (packet->identifier != ident)) |
| 111 | return NULL; |
| 112 | return packet; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| 116 | /* |
| 117 | * vpd_is_valid() - Validates contents of VPD data |
| 118 | * in I2C EEPROM. Returns 1 for |
| 119 | * success or 0 for failure. |
| 120 | */ |
| 121 | static int vpd_is_valid(unsigned dev_addr, unsigned char *buf) |
| 122 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 123 | unsigned num_bytes; |
| 124 | vpd_packet_t *packet; |
| 125 | vpd_t *vpd = (vpd_t *) buf; |
| 126 | unsigned short stored_crc16, calc_crc16 = 0xffff; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 127 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 128 | /* Check Eyecatcher */ |
| 129 | if (strncmp |
| 130 | ((char *) (vpd->header.eyecatcher), VPD_EYECATCHER, |
| 131 | VPD_EYE_SIZE) != 0) { |
| 132 | unsigned offset = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 133 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 134 | if (dev_addr == CONFIG_SYS_DEF_EEPROM_ADDR) |
| 135 | offset += SDRAM_SPD_DATA_SIZE; |
| 136 | printf("Error: VPD EEPROM 0x%x corrupt @ 0x%x\n", dev_addr, |
| 137 | offset); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 138 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 139 | return 0; |
| 140 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 142 | /* Check Length */ |
| 143 | if (vpd->header.size > VPD_MAX_EEPROM_SIZE) { |
| 144 | printf("Error: VPD EEPROM 0x%x contains bad size 0x%x\n", |
| 145 | dev_addr, vpd->header.size); |
| 146 | return 0; |
| 147 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 148 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 149 | /* Now find the termination packet */ |
| 150 | packet = vpd_find_packet(vpd, VPD_PID_TERM); |
| 151 | if (packet == NULL) { |
| 152 | printf("Error: VPD EEPROM 0x%x missing termination packet\n", |
| 153 | dev_addr); |
| 154 | return 0; |
| 155 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 156 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 157 | /* Calculate data size */ |
| 158 | num_bytes = (unsigned long) ((unsigned char *) packet - |
| 159 | (unsigned char *) vpd + |
| 160 | sizeof(vpd_packet_t)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 161 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 162 | /* Find stored CRC and clear it */ |
| 163 | packet = vpd_find_packet(vpd, VPD_PID_CRC); |
| 164 | if (packet == NULL) { |
| 165 | printf("Error: VPD EEPROM 0x%x missing CRC\n", dev_addr); |
| 166 | return 0; |
| 167 | } |
Wolfgang Denk | 3073abd | 2011-12-07 12:19:28 +0000 | [diff] [blame] | 168 | memcpy(&stored_crc16, packet->data, sizeof(ushort)); |
| 169 | memset(packet->data, 0, sizeof(ushort)); |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 170 | |
| 171 | /* OK, lets calculate the CRC and check it */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 172 | #if defined(VXWORKS) |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 173 | calc_crc16 = (0xffff & crc32(buf, num_bytes)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 174 | #else |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 175 | calc_crc16 = (0xffff & crc32(0, buf, num_bytes)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 176 | #endif |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 177 | /* Now restore the CRC */ |
Wolfgang Denk | 3073abd | 2011-12-07 12:19:28 +0000 | [diff] [blame] | 178 | memcpy(packet->data, &stored_crc16, sizeof(ushort)); |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 179 | if (stored_crc16 != calc_crc16) { |
| 180 | printf("Error: VPD EEPROM 0x%x has bad CRC 0x%x\n", |
| 181 | dev_addr, stored_crc16); |
| 182 | return 0; |
| 183 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 184 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 185 | return 1; |
| 186 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 187 | |
| 188 | |
| 189 | /* |
| 190 | * size_ok() - Check to see if packet size matches |
| 191 | * size of data we want. Returns 1 for |
| 192 | * good match or 0 for failure. |
| 193 | */ |
| 194 | static int size_ok(vpd_packet_t *packet, unsigned long size) |
| 195 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 196 | if (packet->size != size) { |
| 197 | printf("VPD Packet 0x%x corrupt.\n", packet->identifier); |
| 198 | return 0; |
| 199 | } |
| 200 | return 1; |
| 201 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 202 | |
| 203 | |
| 204 | /* |
| 205 | * strlen_ok() - Check to see if packet size matches |
| 206 | * strlen of the string we want to populate. |
| 207 | * Returns 1 for valid length or 0 for failure. |
| 208 | */ |
| 209 | static int strlen_ok(vpd_packet_t *packet, unsigned long length) |
| 210 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 211 | if (packet->size >= length) { |
| 212 | printf("VPD Packet 0x%x corrupt.\n", packet->identifier); |
| 213 | return 0; |
| 214 | } |
| 215 | return 1; |
| 216 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 217 | |
| 218 | |
| 219 | /* |
| 220 | * get_vpd_data() - populates the passed VPD structure 'vpdInfo' |
| 221 | * with data obtained from the specified |
| 222 | * I2C EEPROM 'dev_addr'. Returns 0 for |
| 223 | * success or 1 for failure. |
| 224 | */ |
| 225 | int vpd_get_data(unsigned char dev_addr, VPD *vpdInfo) |
| 226 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 227 | unsigned char buf[VPD_EEPROM_SIZE]; |
| 228 | vpd_t *vpd = (vpd_t *) buf; |
| 229 | vpd_packet_t *packet; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 230 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 231 | if (vpdInfo == NULL) |
| 232 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 233 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 234 | /* |
| 235 | * Fill vpdInfo with 0s to blank out |
| 236 | * unused fields, fill vpdInfo->ethAddrs |
| 237 | * with all 0xffs so that other's code can |
| 238 | * determine how many real Ethernet addresses |
| 239 | * there are. OUIs starting with 0xff are |
| 240 | * broadcast addresses, and would never be |
| 241 | * permantely stored. |
| 242 | */ |
| 243 | memset((void *) vpdInfo, 0, sizeof(VPD)); |
| 244 | memset((void *) &vpdInfo->ethAddrs, 0xff, sizeof(vpdInfo->ethAddrs)); |
| 245 | vpdInfo->_devAddr = dev_addr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 246 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 247 | /* Read the minimum size first */ |
| 248 | if (vpd_reader(buf, dev_addr, 0, VPD_EEPROM_SIZE) == NULL) |
| 249 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 250 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 251 | /* Check validity of VPD data */ |
| 252 | if (!vpd_is_valid(dev_addr, buf)) { |
| 253 | printf("VPD Data is INVALID!\n"); |
| 254 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 255 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 257 | /* |
| 258 | * Walk all the packets and populate |
| 259 | * the VPD info structure. |
| 260 | */ |
| 261 | packet = (vpd_packet_t *) &vpd->packets; |
| 262 | do { |
| 263 | switch (packet->identifier) { |
| 264 | case VPD_PID_GI: |
| 265 | printf("Error: Illegal VPD value\n"); |
| 266 | break; |
| 267 | case VPD_PID_PID: |
| 268 | if (strlen_ok(packet, MAX_PROD_ID)) { |
| 269 | strncpy(vpdInfo->productId, |
| 270 | (char *) (packet->data), |
| 271 | packet->size); |
| 272 | } |
| 273 | break; |
| 274 | case VPD_PID_REV: |
| 275 | if (size_ok(packet, sizeof(char))) |
| 276 | vpdInfo->revisionId = *packet->data; |
| 277 | break; |
| 278 | case VPD_PID_SN: |
| 279 | if (size_ok(packet, sizeof(unsigned long))) { |
Wolfgang Denk | 3073abd | 2011-12-07 12:19:28 +0000 | [diff] [blame] | 280 | memcpy(&vpdInfo->serialNum, |
| 281 | packet->data, |
| 282 | sizeof(unsigned long)); |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 283 | } |
| 284 | break; |
| 285 | case VPD_PID_MANID: |
| 286 | if (size_ok(packet, sizeof(unsigned char))) |
| 287 | vpdInfo->manuID = *packet->data; |
| 288 | break; |
| 289 | case VPD_PID_PCO: |
| 290 | if (size_ok(packet, sizeof(unsigned long))) { |
Wolfgang Denk | 3073abd | 2011-12-07 12:19:28 +0000 | [diff] [blame] | 291 | memcpy(&vpdInfo->configOpt, |
| 292 | packet->data, |
| 293 | sizeof(unsigned long)); |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 294 | } |
| 295 | break; |
| 296 | case VPD_PID_SYSCLK: |
| 297 | if (size_ok(packet, sizeof(unsigned long))) |
Wolfgang Denk | 3073abd | 2011-12-07 12:19:28 +0000 | [diff] [blame] | 298 | memcpy(&vpdInfo->sysClk, |
| 299 | packet->data, |
| 300 | sizeof(unsigned long)); |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 301 | break; |
| 302 | case VPD_PID_SERCLK: |
| 303 | if (size_ok(packet, sizeof(unsigned long))) |
Wolfgang Denk | 3073abd | 2011-12-07 12:19:28 +0000 | [diff] [blame] | 304 | memcpy(&vpdInfo->serClk, |
| 305 | packet->data, |
| 306 | sizeof(unsigned long)); |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 307 | break; |
| 308 | case VPD_PID_FLASH: |
| 309 | if (size_ok(packet, 9)) { /* XXX - hardcoded, |
| 310 | padding in struct */ |
| 311 | memcpy(&vpdInfo->flashCfg, packet->data, 9); |
| 312 | } |
| 313 | break; |
| 314 | case VPD_PID_ETHADDR: |
| 315 | memcpy(vpdInfo->ethAddrs, packet->data, packet->size); |
| 316 | break; |
| 317 | case VPD_PID_POTS: |
| 318 | if (size_ok(packet, sizeof(char))) |
| 319 | vpdInfo->numPOTS = (unsigned) *packet->data; |
| 320 | break; |
| 321 | case VPD_PID_DS1: |
| 322 | if (size_ok(packet, sizeof(char))) |
| 323 | vpdInfo->numDS1 = (unsigned) *packet->data; |
| 324 | case VPD_PID_GAL: |
| 325 | case VPD_PID_CRC: |
| 326 | case VPD_PID_TERM: |
| 327 | break; |
| 328 | default: |
| 329 | printf("Warning: Found unknown VPD packet ID 0x%x\n", |
| 330 | packet->identifier); |
| 331 | break; |
| 332 | } |
| 333 | } while ((packet = vpd_get_packet(packet))); |
| 334 | |
| 335 | return 0; |
| 336 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 337 | |
| 338 | |
| 339 | /* |
| 340 | * vpd_init() - Initialize default VPD environment |
| 341 | */ |
| 342 | int vpd_init(unsigned char dev_addr) |
| 343 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 344 | return 0; |
| 345 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 346 | |
| 347 | |
| 348 | /* |
| 349 | * vpd_print() - Pretty print the VPD data. |
| 350 | */ |
| 351 | void vpd_print(VPD *vpdInfo) |
| 352 | { |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 353 | const char *const sp = ""; |
| 354 | const char *const sfmt = "%4s%-20s: \"%s\"\n"; |
| 355 | const char *const cfmt = "%4s%-20s: '%c'\n"; |
| 356 | const char *const dfmt = "%4s%-20s: %ld\n"; |
| 357 | const char *const hfmt = "%4s%-20s: %08lX\n"; |
| 358 | const char *const dsfmt = "%4s%-20s: %d\n"; |
| 359 | const char *const hsfmt = "%4s%-20s: %04X\n"; |
| 360 | const char *const dhfmt = "%4s%-20s: %ld (%lX)\n"; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 361 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 362 | printf("VPD read from I2C device: %02X\n", vpdInfo->_devAddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 363 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 364 | if (vpdInfo->productId[0]) |
| 365 | printf(sfmt, sp, "Product ID", vpdInfo->productId); |
| 366 | else |
| 367 | printf(sfmt, sp, "Product ID", "UNKNOWN"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 368 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 369 | if (vpdInfo->revisionId) |
| 370 | printf(cfmt, sp, "Revision ID", vpdInfo->revisionId); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 371 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 372 | if (vpdInfo->serialNum) |
| 373 | printf(dfmt, sp, "Serial Number", vpdInfo->serialNum); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 374 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 375 | if (vpdInfo->manuID) |
| 376 | printf(dfmt, sp, "Manufacture ID", (long) vpdInfo->manuID); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 377 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 378 | if (vpdInfo->configOpt) |
| 379 | printf(hfmt, sp, "Configuration", vpdInfo->configOpt); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 380 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 381 | if (vpdInfo->sysClk) |
| 382 | printf(dhfmt, sp, "System Clock", vpdInfo->sysClk, |
| 383 | vpdInfo->sysClk); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 384 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 385 | if (vpdInfo->serClk) |
| 386 | printf(dhfmt, sp, "Serial Clock", vpdInfo->serClk, |
| 387 | vpdInfo->serClk); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 388 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 389 | if (vpdInfo->numPOTS) |
| 390 | printf(dfmt, sp, "Number of POTS lines", vpdInfo->numPOTS); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 391 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 392 | if (vpdInfo->numDS1) |
| 393 | printf(dfmt, sp, "Number of DS1s", vpdInfo->numDS1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 394 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 395 | /* Print Ethernet Addresses */ |
| 396 | if (vpdInfo->ethAddrs[0][0] != 0xff) { |
| 397 | int i, j; |
| 398 | |
| 399 | printf("%4sEtherNet Address(es): ", sp); |
| 400 | for (i = 0; i < MAX_ETH_ADDRS; i++) { |
| 401 | if (vpdInfo->ethAddrs[i][0] != 0xff) { |
| 402 | for (j = 0; j < 6; j++) { |
| 403 | printf("%02X", |
| 404 | vpdInfo->ethAddrs[i][j]); |
| 405 | if (((j + 1) % 6) != 0) |
| 406 | printf(":"); |
| 407 | else |
| 408 | printf(" "); |
| 409 | } |
| 410 | if (((i + 1) % 3) == 0) |
| 411 | printf("\n%24s: ", sp); |
| 412 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 413 | } |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 414 | printf("\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 416 | |
Wolfgang Denk | 1da8dba | 2011-12-07 12:19:27 +0000 | [diff] [blame] | 417 | if (vpdInfo->flashCfg.mfg && vpdInfo->flashCfg.dev) { |
| 418 | printf("Main Flash Configuration:\n"); |
| 419 | printf(hsfmt, sp, "Manufacture ID", vpdInfo->flashCfg.mfg); |
| 420 | printf(hsfmt, sp, "Device ID", vpdInfo->flashCfg.dev); |
| 421 | printf(dsfmt, sp, "Device Width", vpdInfo->flashCfg.devWidth); |
| 422 | printf(dsfmt, sp, "Num. Devices", vpdInfo->flashCfg.numDevs); |
| 423 | printf(dsfmt, sp, "Num. Columns", vpdInfo->flashCfg.numCols); |
| 424 | printf(dsfmt, sp, "Column Width", vpdInfo->flashCfg.colWidth); |
| 425 | printf(dsfmt, sp, "WE Data Width", |
| 426 | vpdInfo->flashCfg.weDataWidth); |
| 427 | } |
| 428 | } |