2 * Copyright (C) 2017 PHYTEC Messtechnik GmbH
3 * Author: Wadim Egorov <w.egorov@phytec.de>
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <environment.h>
13 #include <i2c_eeprom.h>
17 static int valid_rk3288_som(struct rk3288_som *som)
19 unsigned char *p = (unsigned char *)som;
20 unsigned char *e = p + sizeof(struct rk3288_som) - 1;
31 int rk_board_late_init(void)
35 struct rk3288_som opt;
38 /* Get the identificatioin page of M24C32-D EEPROM */
39 off = fdt_path_offset(gd->fdt_blob, "eeprom0");
41 printf("%s: No eeprom0 path offset\n", __func__);
45 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
47 printf("%s: Could not find EEPROM\n", __func__);
51 ret = i2c_set_chip_offset_len(dev, 2);
55 ret = i2c_eeprom_read(dev, 0, (uint8_t *)&opt,
56 sizeof(struct rk3288_som));
58 printf("%s: Could not read EEPROM\n", __func__);
62 if (opt.api_version != 0 || !valid_rk3288_som(&opt)) {
63 printf("Invalid data or wrong EEPROM layout version.\n");
64 /* Proceed anyway, since there is no fallback option */
67 if (is_valid_ethaddr(opt.mac))
68 eth_env_set_enetaddr("ethaddr", opt.mac);