blob: e966e9f201abbb3ae8cd5e2c15a11d00ddba442d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Xu Ziyuan1c62d992016-08-01 08:46:19 +08002/*
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
Xu Ziyuan1c62d992016-08-01 08:46:19 +08004 */
5
Jonas Karlmanecc3bd72017-04-22 08:57:54 +00006#include <dm.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06007#include <env.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +00008#include <i2c_eeprom.h>
Simon Glass52559322019-11-14 12:57:46 -07009#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060010#include <net.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000011#include <netdev.h>
12
13static int get_ethaddr_from_eeprom(u8 *addr)
14{
15 int ret;
16 struct udevice *dev;
17
18 ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
19 if (ret)
20 return ret;
21
22 return i2c_eeprom_read(dev, 0, addr, 6);
23}
24
Kever Yang271318a2019-07-22 20:02:14 +080025int rk3288_board_late_init(void)
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000026{
27 u8 ethaddr[6];
28
29 if (get_ethaddr_from_eeprom(ethaddr))
30 return 0;
31
32 if (is_valid_ethaddr(ethaddr))
Simon Glassfd1e9592017-08-03 12:22:11 -060033 eth_env_set_enetaddr("ethaddr", ethaddr);
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000034
35 return 0;
36}