blob: eff3a00c30a81662274a1df9ea1029e21441006a [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
6#include <common.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +00007#include <dm.h>
Simon Glasscb3ef682019-11-14 12:57:50 -07008#include <eeprom.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06009#include <env.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000010#include <i2c_eeprom.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060012#include <net.h>
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000013#include <netdev.h>
14
15static int get_ethaddr_from_eeprom(u8 *addr)
16{
17 int ret;
18 struct udevice *dev;
19
20 ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev);
21 if (ret)
22 return ret;
23
24 return i2c_eeprom_read(dev, 0, addr, 6);
25}
26
Kever Yang271318a2019-07-22 20:02:14 +080027int rk3288_board_late_init(void)
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000028{
29 u8 ethaddr[6];
30
31 if (get_ethaddr_from_eeprom(ethaddr))
32 return 0;
33
34 if (is_valid_ethaddr(ethaddr))
Simon Glassfd1e9592017-08-03 12:22:11 -060035 eth_env_set_enetaddr("ethaddr", ethaddr);
Jonas Karlmanecc3bd72017-04-22 08:57:54 +000036
37 return 0;
38}