1 // SPDX-License-Identifier: GPL-2.0+
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
6 * Based on code developed by:
8 * Copyright (C) 2012 TQ-Systems GmbH
9 * Daniel Gericke <daniel.gericke@tqs.de>
14 #include "kp_id_rev.h"
18 static int eeprom_has_been_read;
19 static struct id_eeprom eeprom;
21 void show_eeprom(void)
27 puts("Module EEPROM:\n");
29 for (i = 0; i <= sizeof(eeprom.id) && 0xff != eeprom.id[i]; ++i)
30 safe_string[i] = eeprom.id[i];
31 safe_string[i] = '\0';
33 if (!strncmp(safe_string, "TQM", 3)) {
34 printf(" ID: %s\n", safe_string);
35 env_set("boardtype", safe_string);
37 puts(" unknown hardware variant\n");
41 for (i = 0; (sizeof(eeprom.serial) >= i) &&
42 (eeprom.serial[i] >= 0x30) &&
43 (eeprom.serial[i] <= 0x39); ++i)
44 safe_string[i] = eeprom.serial[i];
45 safe_string[i] = '\0';
47 if (strlen(safe_string) == 8) {
48 printf(" SN: %s\n", safe_string);
49 env_set("serial#", safe_string);
51 puts(" unknown serial number\n");
56 if (!is_valid_ethaddr(p)) {
57 printf(" Not valid ETH EEPROM addr!\n");
61 printf(" MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
62 p[0], p[1], p[2], p[3], p[4], p[5]);
64 eth_env_set_enetaddr("ethaddr", p);
67 #define I2C_EEPROM_BUS_NUM 1
68 #define I2C_EEPROM_ADDR 0x50
69 #define I2C_EEPROM_ADDR_LEN 2
76 if (eeprom_has_been_read)
79 ret = i2c_get_chip_for_busnum(I2C_EEPROM_BUS_NUM, I2C_EEPROM_ADDR,
80 I2C_EEPROM_ADDR_LEN, &dev);
82 printf("Cannot find EEPROM !\n");
86 ret = dm_i2c_read(dev, 0x0, (uchar *)&eeprom, sizeof(eeprom));
88 eeprom_has_been_read = (ret == 0) ? 1 : 0;
92 int read_board_id(void)
94 unsigned char rev_id = 0x42;
95 char rev_str[32], buf[8];
99 ret = i2c_get_chip_for_busnum(2, 0x22, 1, &dev);
101 printf("Cannot find pcf8574 IO expander !\n");
105 dm_i2c_read(dev, 0x0, &rev_id, sizeof(rev_id));
107 sprintf(rev_str, "%02X", rev_id);
109 printf("BBoard:4x00 Rev:%s\n", rev_str);
110 env_set("boardtype", "ddc");
111 env_set("fit_config", "imx53_kb_conf");
113 printf("BBoard:40x0 Rev:%s\n", rev_str);
114 env_set("boardtype", "hsc");
115 env_set("fit_config", "imx53_kb_40x0_conf");
118 sprintf(buf, "kp-%s", env_get("boardtype"));
119 env_set("boardname", buf);
120 env_set("boardsoc", "imx53");
121 env_set("kb53_rev", rev_str);